>Here is my personal git cheatsheet/reference. Publishing here to be able to access from anywhere, and just in case someone else finds it useful, too.
I keep it as a simple text file, so it is placed here verbatim.
modified -> staged (git add) -> committed (in git db)
See last two commits with diff: git log -p -2See commits in different formats: git log --pretty=<oneline|short|full|fuller>My git log format: git log --pretty:format:"%h %an (%ar): %s"gitk shows log in gui (distributed with git)
Modify last commit: git commit --amend
Working with remotes: ----------
git remote add [shortname] [url]
Multiple remotes: branches are available as [shortname]/[branch]e.g. identra/master
git remote show [remote name]get remote rename [remote name] [new remote name]
git fetch [remote name]git pull # -- works on the remote branch the local branch is set to followgit push [remote name] [branch name]
git remote rm [remote name] # - remove reference to remote repo
git tag # list tagsgit tag -l [pattern] # list tags that match the patterngit tag -a [tag] # add a new taggit tag -a [tag] [short/long commit hash] # add new tag at a previous commit
Tags are not pushed to remote servers, unless you dogit push [remote name] [tag name]git push [remote name] --tags # push all your tags
A branch is simply a pointer to a commit, which gets updated as a new commitis made on top of the commit pointed by the branch (each commit has a pointerto its predecessor).
In other words, a new commit always points to the HEAD at the time it iscommitted as its previous commit (then HEAD gets updated to point to the last commit).
Nice illustration here:
git branch [branch name] # create new branch
A special pointer HEAD points to the local branch you are working on.
git checkout [branch name] # update working copy to given branch, and set HEADgit checkout -b [branch name] # create new branch and update HEAD with one cmd
git merge [branch name] # merge given branch to branch pointed by HEAD
git branch -d [branch name] # remove a branch
Pushing pulling branches:
git fetch [branch name]git push [remote name] [branch name]git push [remote name] :[branch name] # remove a remote branch
Rebasing replays changes from one line of work onto another in the order they were introduced, whereas merging takes the endpoints and merges them together.
git rebase [target branch]
Rebase creates a linear history, by applying the diffs from the branchingpoint of the branch pointed by HEAD, to the given branch in rebase cmd.