Git Cheatsheet
Git Cheatsheet
Git Basics
git init
<directory>
Clone repo located at <repo> onto local machine. Original repo can be
git config
Dene author name to be used for all commits in current repo. Devs
user.name <name>
git add
Stage all changes in <directory> for the next commit. Replace <directory>
<directory>
git commit -m
Commit the staged snapshot, but instead of launching a text editor, use
"<message>"
git status
git log
combined. Use with nothing staged to edit the last commits message.
Rebase the current branch onto <base>. <base> can be a commit
ID, a branch name, a tag, or a relative reference to HEAD.
git reflog
Display the entire commit history using the default format. For
Show a log of changes to the local repository's HEAD. Add --relativedate ag to show date info or --all to show all refs.
Git Branches
git branch
git checkout -b
Create and check out a new branch named <branch>. Drop the -b
<branch>
Remote Repositories +
Undoing Changes
<name> <url>
git revert
git fetch
<commit>
<remote> <branch>
Remove <le> from the staging area, but leave the working directory
git reset <file>
git clean -n
Replace the last commit with the staged changes and last commit
Shows which les would be removed from working directory. Use the -f
<branch>
Visit
+
+
page 1
Additional Options +
git config
git di
Dene the author name to be used for all commits by the current user.
Dene the author email to be used for all commits by the current user.
Set text editor used by commands for all users on the machine. <editor>
arg should be the command that launches the desired editor (e.g., vi).
git reset
Reset staging area to match most recent commit, but leave the working
directory unchanged.
Reset staging area and working directory to match most recent commit
and overwrites all changes in the working directory.
Move the current branch tip backward to <commit>, reset the staging
area to match, but leave the working directory alone.
Same as previous, but resets both the staging area & working directory to
match. Deletes uncommitted changes, and all commits after <commit>.
git log
git log -<limit>
Limit number of commits by <limit> . E.g. "git log -5" will limit to 5
commits
Include which les were altered and the relative number of lines that
were added or deleted from each of them.
git log -p
git log
--author="<pattern>"
git log
--grep="<pattern>"
git reset
git rebase
git rebase -i
<base>
git pull
git pull --rebase
<remote>
Fetch the remotes copy of current branch and rebases it into the local
copy. Uses git rebase instead of merge to integrate the branches.
git push
git log
<since>..<until>
Show commits that occur between <since> and <until>. Args can be a
commit ID, branch name, HEAD, or any other kind of revision reference.
Tags arent automatically pushed when you push a branch or use the
--all ag. The --tags ag sends all of your local tags to the remote repo.
Visit
page 2