Git Notes¶
https://learngitbranching.js.org/
Reference a Commit¶
HEADcurrent commitru49uhcommit hashHEAD^^^3 commits beforeHEADHEAD~33 commits beforeHEAD- use tag name
Navigate¶
git checkout <commit-ref>pointHEADto commit
Branch¶
git checkout -b <branch-name>create and switch to branchgit checkout <branch-name>switch to branchgit branch -f <branch-name> <commit-ref>point<branch-name>to<commit-ref>, useful whenHEADis detachedgit branch -u <remote-branch-name>set current branch to track<remote-branch-name>
Merge¶
git merge <branch-name>merge<branch-name>to current branch
Rebase¶
git rebase <branch-name>rebase current branch to<branch-name>git rebase -i <commit-ref>rebase interactively every commit after<commit-ref>, and point the branch to the last commit after rebase- never rebase a public branch
Reverse Changes¶
git reset HEAD~1(only if not pushed to repo) reverse the branch to one commit beforeHEADgit revert HEADadd a commit that reverse the change made inHEAD
Cherry Pick¶
git cherry-pick <commit-ref> ...copy commits to the current branch
Change a Commit¶
git commit --amendamend changes to last commit
Tag¶
git tag <tag-name> <commit-ref>add tag<tag-name>to<commit-ref>
Others¶
git remote set-url origin <url>change remote url
Working with Remote Repos¶
- when checking out a remote branch (e.g.
origin/master), git will automatically detachHEAD git fetchupdate the remote branch (stored locally to track commits on the remote server) to match commits on the remote servergit pull=git fetch+ merge remote branch just fetched to the local branchgit pull --rebaseto rebase on remote branch instead of merging
git pushupload commits in current branch to remote servergit push origin <branch-name>
Last update:
March 29, 2021
Created: March 25, 2021
Created: March 25, 2021