Commands I use but don't always remember:
git rebase -i HEAD~30 : allows you to modify your last 30 commits (squash, delete, edit, etc) one at a time
git pull -r origin master (same as
git pull --rebase origin master) : rebases your current branch on the specified branch at the same time as pulling the current state of the specified branch
git bisect : amazing command that allows you to find where your code broke by specifying the commit where it works (the good commit) and where it is broken (the bad commit).
git bisect then repeatedly splits the commit history between the two and you identify whether it is good or bad until you find the offending commit
rename a branch:
git branch -m <new-name>
create a new branch from a remote branch:
git checkout -b <name_of_new_branch> origin/<name_of_branch_to_come_from>
git stash save setup_changes (to name a git stash for later)
- to apply do
git stash <name> apply
set your branch to exactly match the remote branch:
If you want to save your current branch's state before doing this (just in case), you can do:
git commit -a -m "Saving my work, just in case"
git branch my-saved-work
Now your work is saved on the branch "my-saved-work" in case you decide you want it back (or want to look at it later or diff it against your updated branch).
Note that the first example assumes that the remote repo's name is "origin" and that the branch named "master" in the remote repo matches the currently checked-out branch in your local repo.
git fetch origin
git reset --hard origin/master