No matter whether you’ve just taken a first look at a Git tutorial or already have some ex­per­i­ence in using the version control system, with a clear Git cheat sheet, you’ll always have all the Git commands and codes at a glance.

Git Cheat Sheet

Version and in­stall­a­tion

To check which version of Git is currently on your computer, use the following command:

git --version

If you don’t find a version, you can download Git using the following links:

Git is open source and free of charge.

Con­fig­ur­a­tion

You need a username and a valid email address to work with Git. Here’s how to configure both:

Specify a name git config --global user.name "your name"
Enter your email address git config --global user.email "sample­ad­dress@sample.com"

Create a re­pos­it­ory

Create a new re­pos­it­ory or download an existing re­pos­it­ory.

Create and name a new local re­pos­it­ory git init sample name
Copy an existing re­pos­it­ory and its history with Git clone git clone "http://samples­ite.com"

Make changes

You can make, track and add changes.

Show the status of the directory git status
Show objects git show
Add a file git add sample file
Add all files from a re­pos­it­ory git add*
Show all new or changed files with Git diff git diff
Show any changes between the staging area and the re­pos­it­ory git diff --staged
Track changes after commit git diff HEAD
Show dif­fer­ences between index and current stage git reset sample file
Add currently indexed files per­man­ently to the version history with Git commit git commit -m "Ex­plan­a­tions for the changes"

Branches

Group changes into branches and integrate new features.

Create and edit

Create a new branch git branch sample name
List all branches git branch --list
Delete a branch git branch -d
Remove a remote branch git push origin --delete
Rename a branch git branch -m

Switch branch

Switch to another branch with Git checkout git checkout other branch
Create a new branch and switch to it git checkout -b

Merge and fetch

Merge history of a branch with the current branch git merge sample name
Register external re­pos­it­ory and swap history git fetch "http://www.samples­ite.com"
Fetch all branches git fetch -all
Register a local re­pos­it­ory git fetch origin

Cache

Put current changes in your working directory into stash for later use with Git stash git stash
Save changes with an ex­plan­a­tion git stash save "insert ex­plan­a­tion here"
List stashes git stash list
Make new changes to a stash git stash apply
Track changes to the stash git stash show
Apply and delete stash directly git stash pop
Discard in­ter­me­di­ate stashes git stash drop
Delete all available stashes git stash clear
Save to a separate branch git stash branch sample branch

Push and pull

Use Git push and Git pull to commit to or retrieve from the remote server.

Integrate external branch with current local branch git push "http://www.samples­ite.com" local sample branch
Transfer data to the remote server git push origin master
Force push git push -f
Remove remote branch via push git push origin --delete sampl­eb­ranch
Pull history from external re­pos­it­ory git pull
Pull data from server git pull origin master

Log

You check the history of a commit with Git log.

Show all commits for a branch git log
Limit the number of commits (in this example to three) git log -3
Search commits from a specific author git log --author= "sample name"
Show commits for a specific time period git log <since>…<until>
Show commits for a specific file git log sample file

Revert changes

You have two options to revert changes — Git revert or Git reset. For the latter, you can choose between the options 'soft', 'hard' and 'mixed'.

Modify existing commit git commit --amend
Remove file from staging area git reset HEAD sample­file or git restore --staged sample­file
Discard local changes to a file in the staging area git checkout --sample­file oder git restore sample­file
Tip

Whether a static website or a single-page ap­plic­a­tion, with Deploy Now from IONOS, you deploy your project in just three steps. During the process, you’ll benefit from useful features such as automatic framework detection and high scalab­il­ity.

Go to Main Menu