Home  >  Article  >  Development Tools  >  Summary of commonly used Git commands [recommended collection]

Summary of commonly used Git commands [recommended collection]

藏色散人
藏色散人forward
2021-07-17 15:52:192061browse

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

Create a new branch and switch to this branch

git checkout -b new_branch

Switch to the main branch Branch, merge other branches

git checkout master
git merge new_branches

Submit changes to the staging area

git add -A

Submit changes to the local repository

git commit -m "备注"

Delete files in the current directory that are not tracked

git clean -df

Commit changes to the server repository

git push

Test the code and roll back

First, the version tag

git add -Agit commit -m "版本标记"

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

git checkout .

Check the status:

git status

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

git clean -f -d

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

git status

Find that everything is clean.

Initialization settings

Add folder contents to version management

git init

Set email address

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

Set user name

git config --global user.name "Your Name"

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

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

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!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete