This post is to archive some commonly used git commands.
Clone
1 2
| $ git clone -b <branch> <repo> [dir]
|
Merge
1 2 3 4 5 6 7 8 9 10 11 12
| $ git checkout master
$ git merge dev
$ git merge -X ours dev
$ git merge -X theirs dev
|
Commit
Rebase
1 2 3
| $ git rebase -i HEAD~2
|
Checkout
1 2 3 4 5 6 7 8 9 10 11
| $ git checkout -b <branch>
$ git checkout -b <local-branch> origin/<remote-branch>
$ git checkout -- <file>
$ git checkout <branch>
|
Branch
1 2 3 4 5 6 7 8 9 10 11
| $ git branch
$ git branch <branch>
$ git branch -D <branch>
$ git branch -d <branch>
|
Push
1 2 3 4 5
| $ git push -f
$ git push --set-upstream origin <remote-branch>
|
Reset
Clean
Submodule
If you need to put a git repo inside another git repo, treat the inside repo as a git submodule.
1
| $ git submodule add [OPTIONS] <repo> <path>
|