I have used Git for a long time, but many commands are not often used, easy to forget, think about it or record it, build your own git knowledge base, when you use it in the future, it is also convenient to find, I will continue to update this blog.
1. Initialization
Clone directly to the specified branch:
git cloneAddress -b Branch nameCopy the code
Configure Git globally:
Git config --global user.email git config --global user.emailCopy the code
Initialize the local Git repository:
git init
Copy the code
View warehouse Status
git status
Copy the code
Undo all local changes
git reset --hard$HEAD
Copy the code
Manually add file changes to the staging area
git add .
Copy the code
Submit the code for this change (1)
git commit -a
Copy the code
Enter the description of this submission after I, then press Esc and enter :wq to save
Submit the code for this change (1)
Git commit -mCopy the code
Get the latest code on the network side
git pull
Copy the code
Submit the local repository code to the network side
git push
Copy the code
Second, the branch
Creating a Branch
git branch a
Copy the code
Switch to branch A
git checkout a
Copy the code
Create new branch A and switch to branch A
git checkout -b a
Copy the code
Delete branch A
git branch -d a
Copy the code
Forcibly delete branch A
git branch -D a
Copy the code
See the branch
git branch
Copy the code
Merging branches
For example, if we want to merge the code from branch A into branch B, we need to switch to branch B first
git checkout b
Copy the code
then
git merge a
Copy the code
This merges the contents of branch A into branch B
3. Remote upload operation
1. The local git repository does not exist. Synchronize the data to GitHub
git init
git add .
git commit -aGit pull --rebase origin master Git push -u origin masterCopy the code
2. A Local Git repository exists and the remote address is not bound. Therefore, the git repository is synchronized to GitHub
Git remote add origin Github addressCopy the code
3. A Local Git repository exists and a remote address has been bound. You need to change the address and synchronize it to GitHub
git remote set- URL origin New Github address or git remote rm origin git remote add origin New Github addressCopy the code
Git branch-dev: git branch-dev: git branch-dev: git branch-dev: git branch-dev: git branch-dev: git branch-dev Git push -u origin dev is required to submit the code below dev to Github
The 2017-8-18 update
I have seen the hints given in gITlab today, and I will post them here:
Create a new repository
git cloneGit addresscd i5oncall
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Copy the code
Existing Folder or Git repository
cdExisting_folder git init git remote add origin Git add. Git commit Git push -u origin masterCopy the code
You can follow me in the following ways:
- CSDN
- The Denver nuggets
- Personal blog