Login

Git cheat sheet

AO
Adama OUATTARA
May 4, 2023, 9:14 PM

Co-authors : 
WA
Wassim Abou-Jaoudé
BM
Benjamin Maisonneuve

Git is the open source decentralized version control system. This cheat sheet provides quick access to commonly used Git command instructions.

INSTALL GIT

Git distributions for Linux and POSIX systems are available from the official Git SCM website : http://git-scm.com

INSTALL GitHub GIT

GitHub provides desktop clients that include a graphical interface for the most common manipulations and an automatically updating command line edition of Git for advanced scenarios.

TOOL SETUP

Configure user information for all local repositories
Define the name you want associated with all your commit operations
$ git config --global user.name "[name]"
Define the email you want associated with all your commit operations
$ git config --global user.email "[email]"
Enable colorization of command line output
$ git config --global color.ui auto

CREATE REPOSITORIES

Start a new repository or get one from an existing URL
Create a local repository from the specified name
$ git init [project-name]
Download a project and all its version history
$ git clone [url]

MAKING CHANGES

View changes and perform a commit operation
List all new files and modified files to commit
$ git status
Show file changes that are not yet indexed
$ git diff
Add a snapshot of a specific file, in preparation for version tracking
$ git add [fichier]
Add a snapshot of all the files, in preparation for version tracking
$ git add
Show file differences between the indexed version and the latest version
$ git diff --staged
Remove a specific file from the index, but keep its content
$ git reset [file]
Commit file snapshots permanently in version history
$ git commit -m "[message]"

BRANCHES

Manage branches
Get the list of all local branches in the current repository
$ git branch
Create a new branch
$ git branch [branch-name]
Switch to the specified branch and update the working directory
$ git checkout [branch-name]
Merge in the current branch the history of the specified branch
$ git merge [branch-name]
Delete a branch
$ git branch -d [branch–name]

SYNCHRONIZE CHANGES

Synchronize version history
Get all history from the named repository
$ git fetch [repository-name]
Get all history from the remote repository and incorporate changes in the local current repository
$ git pull
$ git push [branch-name] pull a specified remote branch
Send all local branch commits to the remote repository (GitHub, Gitlab or other Git servers)
$ git push
$ git push [branch-name] send a specified local branch

RESET COMMITTING

Correct errors and manage correction history
Undo all commits after a commit, keeping changes locally
$ git reset [commit]
Delete all history and changes made after the specified commit
$ git reset --hard [commit]