This cheat sheet is available in 25+ languages. Visit github.com/github/training-kit to access translations.
Installation
GitHub Desktop
For a graphical interface, download GitHub Desktop at desktop.github.comGit for All Platforms
Download the command-line tool at git-scm.comConfigure Tooling
Configure user information for all local repositories.Set your name
Set your name
Set your email
Set your email
Enable colorization
Enable colorization
Branches
Branches are an important part of working with Git. Any commits you make will be made on the branch you’re currently “checked out” to. Usegit status to see which branch that is.
| Command | Description |
|---|---|
git branch [branch-name] | Creates a new branch |
git switch -c [branch-name] | Switches to the specified branch and updates the working directory |
git merge [branch] | Combines the specified branch’s history into the current branch. This is usually done in pull requests, but is an important Git operation. |
git branch -d [branch-name] | Deletes the specified branch |
Create Repositories
A new repository can either be created locally, or an existing repository can be cloned. When a repository was initialized locally, you have to push it to GitHub afterwards.Initialize a new repository
Initialize a new repository
git init command turns an existing directory into a new Git repository inside the folder you are running this command. After using the git init command, link the local repository to an empty GitHub repository using the following command:Clone an existing repository
Clone an existing repository
The .gitignore File
Sometimes it may be a good idea to exclude files from being tracked with Git. This is typically done in a special file named.gitignore. You can find helpful templates for .gitignore files at github.com/github/gitignore.
Synchronize Changes
Synchronize your local repository with the remote repository on GitHub.com| Command | Description |
|---|---|
git fetch | Downloads all history from the remote tracking branches |
git merge | Combines remote tracking branches into current local branch |
git push | Uploads all local branch commits to GitHub |
git pull | Updates your current local working branch with all new commits from the corresponding remote branch on GitHub. git pull is a combination of git fetch and git merge |
Make Changes
Browse and inspect the evolution of project files.View history
View history
Compare changes
Compare changes
Stage and commit
Stage and commit
Redo Commits
Erase mistakes and craft replacement history.| Command | Description |
|---|---|
git reset [commit] | Undoes all commits after [commit], preserving changes locally |
git reset --hard [commit] | Discards all history and changes back to the specified commit |
Glossary
git
git
An open source, distributed version-control system
GitHub
GitHub
A platform for hosting and collaborating on Git repositories
commit
commit
A Git object, a snapshot of your entire repository compressed into a SHA
branch
branch
A lightweight movable pointer to a commit
clone
clone
A local version of a repository, including all commits and branches
remote
remote
A common repository on GitHub that all team members use to exchange their changes
fork
fork
A copy of a repository on GitHub owned by a different user
pull request
pull request
A place to compare and discuss the differences introduced on a branch with reviews, comments, integrated tests, and more
HEAD
HEAD
Representing your current working directory, the HEAD pointer can be moved to different branches, tags, or commits when using
git switch