git checkout -b cool-new-branch ~ create new branch and switch to it git checkout cool-branch-name ~ Switch to another branch git checkout -- * ~ Clear tracked modified files not committed git checkout -- foo/bar/file.cs ~ Clear tracked modified `file.cs` not committed git checkout [revision] ~ Fall back to revision (run 'git log' to see commits) ~ run `git switch -` to revert the head detachment
git pull ~ Pull anything new from remote server (for origin) git pull upstream master ~ Pull anything new from the remote name (upstream) on branch master git pull upstream master --rebase ~ Rebase the current branch on top of the upstream branch after fetching.
git push ~ Push staged and committed to remote (for origin) git push -d origin cool-branch-name ~ Push and delete the branch git push origin master ~ Push changes to origin, you will do this if you have run `git pull upstream master`
Reapply commits on top of another base tip, normally master :D
1 2 3 4 5
git checkout master ~ switch to master branch git pull upstream master --rebase ~ rebase your copy of master with any changes in `upstream` git checkout cool-branch-name ~ switch to feature branch git rebase master ~ rebase your feature branch with master git push origin cool-branch-name -f ~ when pushing you may need to force push if you are now changing history on pushed branches
If there are conflicts
1 2 3 4
git status ~ to see which files are unmerged # ... resolve conflict git add <conflicted_files> ~ mark files as resolved, you could also `rm` if you dont want the file git rebase --continue
If this are totally sideways run git rebase --abort
You can jump any amount of heads below, example HEAD~2 will jump back 2.
1 2 3
git reset HEAD~1 --mixed ~ Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. git reset head --hard ~ clear the local changes that were reset above (that are now un-commited) git push origin cool-branch-name -f ~ forces the changes you did with the above resets to origin
This was useful when I had run git commit --amend on the wrong head