Skip to main content

Commands Cheat Sheet

A quick reference guide of common Git commands.

Initialization & Cloning

DescriptionCommandNotes
Initialize in current directorygit initInitializes a new Git repository in the current directory.
Initialize a new repositorygit init <name>Creates a new directory with the specified name and initializes it as a Git repository.

Example: git init hello-world
Clone a repositorygit clone <url>Clones an existing repository.

Example: git clone https://github.com/github/docs.git
Clone with SSHgit clone <url>Clones using SSH for authentication.

Example: git clone git@github.com:github/docs.git
Clone into specific directorygit clone <url> <directory>Clones into a specified directory.

Example: git clone https://github.com/github/docs.git github-docs
info

HTTPS is common method for cloning repositories, while SSH is often used for contributors with write access. There is also a difference in URL format between the two methods.

ProtocolFormatExample
HTTPShttps://<host>/<user>/<repository>.githttps://github.com/github/docs.git
SSHgit@<host>:<user>/<repository>.gitgit@github.com:github/docs.git

Configuration

info

--global applies the setting for all repositories for the current user. Omitting it sets the configuration for the current repository only, but requires being inside a Git repository.

DescriptionCommandNotes
Set user namegit config --global user.name "<name>"Sets the global username for commits.

Example: git config --global user.name "adam"
Set user emailgit config --global user.email "<email>"Sets the global email for commits.

Example: git config --global user.email "adam@example.com"
Set default text editorgit config --global core.editor <editor>Sets the default text editor for Git.

Example: git config --global core.editor /usr/bin/vim
Set default branch namegit config --global init.defaultBranch <name>Sets the default branch name for new repositories.

Example: git config --global init.defaultBranch main
Set aliasgit config --global alias.<alias> <command>Creates a shortcut for a Git command.

Example: git config --global alias.cl clone
Remove aliasgit config --global --unset alias.<alias>Removes a previously set alias.

Example: git config --global --unset alias.cl
View specific config valuegit config --global user.nameDisplays the value of a specific configuration setting.
View configurationgit config --global --listLists all Git configuration settings.
Edit configuration filegit config --global --editOpens the global config file in the default editor.

Staging & Committing

DescriptionCommandNotes
Check statusgit statusDisplays the status of the working directory and staging area.
Stage specific filegit add <file>Stages a specific file.

Example: git add README.md
Stage specific filesgit add <file1> <file2>Stages multiple specific files.

Example: git add README.md index.html
Stage all changesgit add .Stages all modified and new files.
Commit staged changesgit commit -m "<message>"Commits staged changes with a message.

Example: git commit -m "Initial commit"
Amend last commitgit commit --amend -m "<message>"Amends the last commit with a new message.

Example: git commit --amend -m "Updated commit message"