Git Cheat Sheet

ADVERTISEMENT

Git Cheat Sheet
Git Basics
Rewriting Git History
Create empty Git repo in specified directory. Run with no arguments to
Replace the last commit with the staged changes and last commit
git init
git commit --amend
initialize the current directory as a git repository.
<directory>
combined. Use with nothing staged to edit the last commit’s message.
Clone repo located at <repo> onto local machine. Original repo can be
Rebase the current branch onto <base>. <base> can be a commit
git rebase <base>
+
git clone <repo>
located on the local filesystem or on a remote machine via HTTP or SSH.
ID, a branch name, a tag, or a relative reference to HEAD.
git config
Define author name to be used for all commits in current repo. Devs
Show a log of changes to the local repository's HEAD. Add --relative-
git reflog
+
user.name <name>
commonly use --global flag to set config options for current user.
date flag to show date info or --all to show all refs.
Stage all changes in <directory> for the next commit. Replace <directory>
git add
Git Branches
with a <file> to change a specific file.
<directory>
Commit the staged snapshot, but instead of launching a text editor, use
List all of the branches in your repo. Add a <branch> argument to
git commit -m
git branch
<message> as the commit message.
create a new branch with the name <branch>.
"<message>"
git checkout -b
Create and check out a new branch named <branch>. Drop the -b
List which files are staged, unstaged, and untracked.
git status
<branch>
flag to checkout an existing branch.
Display the entire commit history using the default format. For
+
git log
Merge <branch> into the current branch.
git merge <branch>
customization see additional options.
+
Show unstaged changes between your index and working
Remote Repositories
git diff
+
directory
Create a new connection to a remote repo. After adding a remote, you
git remote add
Undoing Changes
<name> <url>
can use <name> as a shortcut for <url> in other commands.
Create new commit that undoes all of the changes made in
Fetches a specific <branch>, from the repo. Leave off <branch> to
git revert
git fetch
<commit>, then apply it to the current branch.
fetch all remote refs.
<remote> <branch>
<commit>
Remove <file> from the staging area, but leave the working directory
Fetch the specified remote’s copy of current branch and immediately
git pull <remote>
+
+
git reset <file>
unchanged. This unstages a file without overwriting any changes.
merge it into the local copy.
Shows which files would be removed from working directory. Use the -f
Push the branch to <remote>, along with necessary commits and
git push <remote>
+
git clean -n
flag in place of the -n flag to execute the clean.
objects. Creates named branch in the remote repo if it doesn’t exist.
<branch>
page 1
Visit
for more information, training, and tutorials

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 2