My Git cheat sheet to handle
git statusgit diffgit diff --cachedgit log -pTip: use -- FILENAME to list all the changes made to the given file.
git add .git add FILENAMETip: use -p to go over all changes in that file by chunks so you can still choose what to stage or not.
git commit --amend --no-editgit commit --fixup REFTip: will look like a normal commit on top of your branch. We can rebase these changes in the commit where it belongs to.
git checkout -b BRANCH_NAMEgit branchTip: use -a to list all remote and local branches
git branch -d BRANCH_NAMETip: The -d option is an alias for --delete, which only deletes the branch if it has already been fully merged in its upstream branch. You could also use -D, which is an alias for --delete --force, which deletes the branch "irrespective of its merged status.
git fetch origin
git reset --hard origin/masterThis command makes this for you:
- Save your uncommitted changes locally with
git stash. - Local changes you made will be rebased on top of the remote changes.
- Return your uncommitted changes locally again.
git pull REMOTE_ORIGIN TARGET_BRANCH --rebase --autostashgit fetch really only downloads new data from a remote repository - but it doesn't integrate any of this new data into your working files. Fetch is great for getting a fresh view on all the things that happened in a remote repository.
git fetch --allTip: add --prune for cleaning outdated local branches
git push origin HEAD --force-with-leaseTip: create an alias like git fp for this in your .gitConfig
git rebase REF -i --autosquashTip: use -i to handle it interactive yourself
git rebase -i origin/master --autosquashTip: option --autosquash to handle fixups the correct way can be added as default in your .gitconfig
git rebase --abortgit rebase --continuegit stashgit popAdd the commit with REF to your branch
git cherry-pick REFRevert a commit with REF from your branch
git revert REFgit refloggit show BRANCH_NAME:FILE_NAMEgit show <COMMIT> -- <FILE> | git apply -RTip: first view file changes without | git apply -R
rm -rf .git