Commands I use but don't always remember:
git push --force-with-lease: doesn't overwrite anything the way
git push -f does
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
git config --global pull.ff only will tell git to only pull if it is a fast forward pull. This will stop accidental merges.
- That is the config command,
--globalmeans it will be your global git config. If you omit the global flag then it will only affect your current git project. You can pass
--ff-onlyon the command line to override the configured default per invocation.
pullhas a few options:
pull.rebase false(default) does a merge,
pull.rebase truewill assume the
--rebaseflag when pulling, and
pull.ffwhich will rebase in fast forward only fashion.
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
tell git to ignore changes to a file
git update-index --assume-unchanged <file_name>