New branch shortcut
// Pull the new branch from release:Git checkout release git pull git checkout -b// Link to a remote repository:"Git push --set-upstream origin XXXXX"// Commit the first time: git add. commit again, then push again
Copy the code
The code version is rolled back
[Git Local Version Rollback]
Git reset --hard commit-id ' '(rollback to commit-id, Git reset --hard HEAD~3 (roll back the last 3 commit)Copy the code
Git Remote version rollback
Git push Origin HEAD --forceCopy the code
The following command can also implement remote version rollback
git reset --hard HEAD~1
git push --force
Copy the code
Merging branches
Let’s say we’re on the dev branch, just developed the project, and execute the following command:
git add .
git commit -m 'Submitted Remarks'
git push -u origin dev
Copy the code
To merge the dev branch into the master branch, do the following:
- 1, first switch to the master branch
git checkout master
- 2. Pull the code from the remote master if it is developed by multiple people
git pull origin master
- 3, then we merge dev branch code into master
git merge dev
- 4. Then check the status and execute the submit command
git status
On branch master
Your branch is ahead of 'origin/master' by 12 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean
You have 12 commit files that need to be pushed to the remote master
Copy the code
Finally, execute the submit command below
git push origin master
- 5 Other Commands
- Update the remote branch list
git remote update origin –prune 2. Check all branches git branch -a
Example Delete remote branch Chapater6
git push origin --delete Chapater6
Example Delete local branch Chapater6
git branch -d Chapater6
Branch operation
Delete a local branch safely
Git branch -d Indicates the branch to be deleted
Example Forcibly delete a local branch
Git branch -d Indicates the branch to be deleted
Delete all local branches that have been merged into the master branch
git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -d
Delete all local branches where origin no longer exists
git remote prune orign
Merge branch A into the current branch and create A COMMIT for the merge
Git merge A branch
Merge branch A into branch B and create A COMMIT for the merge
Git merge branch A and branch B
Rebase the current branch against the B branch to incorporate the B branch into the current branch
Git rebase B branch
Configure the operating
Global configuration
Git config --global user.name 'git config --global user.email'
Current Warehouse configuration
Git config --local user.name 'git config --local user.email'
View the current repository configuration
git config --local --list
Delete the current repository configuration
Git config --unset --local Specifies the configuration item to be deleted
The remote interaction
View all remote repositories
git remote -v
Add a remote repository
git remote add url
Example Delete a remote repository
Git remote Remove name of remote
Rename the remote repository
Git remote rename old name new name
Pull all branch and label changes from the remote end to the local end
git fetch remote
Merge changes in remote branches to local branches
Git pull Origin name
Push the local branch to the remote end
Git push Origin branch name
Example Delete a remote branch
Git push remote --delete remote branch name git push remote: indicates the name of a remote branch