100% found this document useful (1 vote)
39 views2 pages

GIT Cheat Sheet by Hello, World!

This is a sheet which could summarize your entire git learning
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
39 views2 pages

GIT Cheat Sheet by Hello, World!

This is a sheet which could summarize your entire git learning
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

15

Minutes

Git Cheat Sheet GIT BASICS

Add the file to the staging area


for next commit. Use . in place
git add <file> of file to add all changed files
WHAT IS GIT? INSTALLATION from the current directory to
the staging area.

Git is a free and open source Git for All Platforms: List the staged, unstaged &
git status
distributed version control http://git-scm.com untracked files
system designed to handle
everything from small to very Debian/Ubuntu:
List current branch’s commit
large projects with speed and In terminal type, git log
history
efficiency. sudo apt-get install git

List your branches. a* will


git branch appear next to currently active
branch.
15
Commands
Minutes

Create a new branch named


“branch”. -b flag is used to
git checkout -b <branch>
checkout the existing branch &
go to new branch.
CONFIGURATION/ SETUP

Set the name that will be visible with


git config --global user.name “Your Name”
your commits & tags

Set the email that will be visible with


git config --global user.email “[email protected]
your commits & tags DAY TO DAY USE

Set color for git output/ command


git config --global color.ui auto
line
Merge branch named “branch”
git merge <branch>
into current branch

Remove file from working


START A PROJECT git rm <file>
directory and staging area

Create empty git repository in the specified directory. Run with no Show changes between working
git init <directory>
arguments to initiate the current directory as a git repository.
git diff
directory and staging area

git clone <url> Set the email that will be visible with your commits & tags Add the file to the staging area
for next commit. Use . in place of
git add file to add all changed files from
the current directory to the
staging area.

GIT PULL Remove selected branch, if it is


git checkout -d <branch> already merged into any other. -
D instead of -d forces deletion.
Fetch the remote’s copy of current branch and rebases it
git pull --rebase <remote> into the local copy. Uses git rebase instead of merge to
integrate the branches.
GIT DIFF
REMOTE REPOSITORIES
git diff HEAD Show difference between working directory and last commit.

git diff --cached Show difference between staged changes and last commit. Create a new connection
git remote add <name> <url> to a remote repo

Fetch specific branch from


remote repo. Leave off
git fetch <remote> <branch>
branch to fetch all remote
UNDOING CHANGES refs

Delete remote refs that


Create new commit that undoes all of the changes made in , then apply it to git fetch --prune <remote>
git revert <commit> were removed from the
the current branch.
remote repo
Shows which files would be removed from working directory. Use the -f flag
git clean -n
in place of the -n flag to execute the clean. Fetch the copy of remote
git pull <remote> repo and merge it into local
git commit --amend Replace the last commit with the staged changes and last commit combined. copy
Use with nothing staged to edit the last commit’s message.

Push the branch to


<remote>, create a branch
git push <remote> <branch>
named “branch” if it doesn’t
exist in remote repo

TEMPORARY COMMITS
Push local branch to remote
git push -u <remote> <branch> repo & sets its copy as an
upstream
git stash Put current changes in your working directory into stash for later use.

git stash pop Apply stored stash content into working directory, and clear stash.

git stash drop Delete a specific stash from all your previous stashes.

REWRITE HISTORY

Show a log of changes to


git reflog
GIT REBASE the local repo’s HEAD

Rebase the current branch


Interactively rebase current branch onto . Launches editor to enter Clear staging area, rewrite
onto <base>. Base can be a
git rebase -i <base> commands for how each commit will be transferred to the new working tree from specified
git rebase <base> commit ID, branch name, tag
base. commit or a relative reference to
HEAD

Remove from the staging


area, but leave the working
git reset <file> directory unchanged. This
GIT PUSH
unstages a file without
overwriting any changes.

Forces the git push even if it results in a non-fast-forward merge. Do not use Clear staging area, rewrite
git push <remote> --force the --force flag unless you’re absolutely sure you know what you’re doing git reset —hard <commit> working tree from specified
commit.

git push <remote> --all Push all of your local branches to the specified remote.

Tags aren’t automatically pushed when you push a branch or use the --all flag.
git push <remote> --tags
The --tags flag sends all of your local tags to the remote repo

Hello, World!

You might also like