Home > Development Tools > git > body text

Summary of commonly used Git commands [recommended collection]

藏色散人
Release: 2021-07-17 15:52:19
forward
2070 people have browsed it

Git is an open source distributed version control system used to handle any project, small or large, agilely and efficiently. Git is an open source version control software developed by Linus Torvalds to help manage Linux kernel development. Git is different from commonly used version control tools such as CVS and Subversion. It uses a distributed version library and does not require server-side software support.

Common Git commands

Switch to the main branch

git checkout master
Copy after login

Create a new branch and switch to this branch

git checkout -b new_branch
Copy after login

Switch to the main branch Branch, merge other branches

git checkout master
git merge new_branches
Copy after login

Submit changes to the staging area

git add -A
Copy after login

Submit changes to the local repository

git commit -m "备注"
Copy after login

Delete files in the current directory that are not tracked

git clean -df
Copy after login

Commit changes to the server repository

git push
Copy after login

Test the code and roll back

First, the version tag

git add -Agit commit -m "版本标记"
Copy after login

because after that, we Will roll back to this place.
Discard all file modifications:

git checkout .
Copy after login

Check the status:

git status
Copy after login
Copy after login

If you find that there are still some newly created files, then:

git clean -f -d
Copy after login

(Force to clean the files, even Clear the folder together)
Then check again:

git status
Copy after login
Copy after login

Find that everything is clean.

Initialization settings

Add folder contents to version management

git init
Copy after login

Set email address

git config --global user.email "you@example.com"
Copy after login

Set user name

git config --global user.name "Your Name"
Copy after login

Generate SSH public key

Many Git servers use SSH public keys for authentication.
If you want to provide an SSH public key to the Git server, you must generate one yourself first.
If you are not sure whether you have the SSH public key, you can enter

cd ~/.ssh && ls
Copy after login

in Git Bash to check.
If you see the pair of files id_rsa and id_rsa.pub, it proves that your computer has the key.
.pub is your public key, and the other is the corresponding private key.
If such a file cannot be found or the .ssh directory does not exist at all, then you need to enter the

ssh-keygen
Copy after login

command in Git Bash to create them.
If you do not want to use a password to protect your key, just leave it blank when creating the query (press Enter to execute directly).
After that, you can use the universal notepad to open id_rsa.pub, copy the contents, and add it to the Git server or website.

Recommended: "Git Tutorial"

The above is the detailed content of Summary of commonly used Git commands [recommended collection]. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
git
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!