Git Cheatsheet – Frequently Used Git Commands

Git Cheatsheet

A cheatsheet is a crisp set of notes, or commands used as a quick reference. Git is the most popular modern version control system (open-source and free). The below table contains the list of most frequently used Git commands. We present the Git commands with the syntax and the purpose of use. Also, the commands are grouped by their categories. To get a downloadable and printable Git Cheatsheet in PDF format, jump to the next section.

#CategoryCommandPurpose
1Setupgit config <key> <value>Configure various Git options such as username, user email, etc. in the current repository
2git config –global <key> <value>Globally (all local repos) configure various Git options such as username, user email, etc.
3git initInitialize a new local Git repository. Turn a directory into a Git repository.
4git clone <url>Create a local working copy of an existing remote repository
5Statusgit statusDisplay the state of the local repository (what is added, modified, and deleted)
6Fetchgit fetchFetch the branch and commit details from the remote repositories without copying files
7git pull origin <branch>Fetch and merge the latest changes from the remote repository to the local repository
8git checkout <branch>Checkout an existing branch and switch to it
9git checkout <commit>Checkout a specific commit
10Branchgit branchList all local branches and determine which branch the local repository is on
11git branch -aList all branches, including the remote ones
12git branch <name>Create a new branch, but remain in the current branch
13git branch -d <branch>Delete a branch
14git switch <branch>Switch to a branch
15git checkout -b <branch>Create a new branch and immediately switch to the new branch
16Developgit add <file1> <file2> <file3>Add specified files to the staging area in order to commit subsequently
17git add –allAdd all files that are not staged to the staging area in order to commit subsequently
18git cleanRemove untracked files from the local repository
19git rm <file>Remove tracked files or directories from the index or from the working directory
20git mv <file1> <file2>Rename a file and update the index
21git checkout <file>Discard changes made to the file in the local repository
22git commit -m <message>Save the changes to the local repository
23git commit –amendAmend (update) the most recent commit
24Submitgit push origin <branch>Push (submit) the content of commits from the local repository to the remote repository
25Syncgit merge <branch>Integrate changes from one branch to another branch. Creates a merge commit.
26git rebase <branch>Integrate changes from one branch to another branch. Rewrites commit history.
27Analyzegit logShow the commit history
28git show <commit>Show details of a specific commit
29git blame <file>Show what revision and author last modified each line of a file
30git diffView changes between the working directory and the staging area
31git diff <file>View changes in a file
32git diff <branch1> <branch2> <file>View changes of a file between two branches
33git diff <commit1> <commit2> <file>View changes of a file between two commits
34Revertgit reset –hard <commit>Undo changes to files in the working directory. Other options are --soft and --mixed.
35git reset –hard HEAD~2Move the current branch backward by 2 commits
36git revert HEAD~2Revert (Undo) the 2nd to last commit and create a new commit
37Stashgit stashSave changes made when they are not in a state to commit them
38git stash listLists all stashes
39git stash popApplies the top stashed element and removes it
40git stash applyApplies the top stashed element and preserves it
41git remote <cmd> <name> <url>Add a remote repository
42git remote -vList named remote repositories
43Taggit tagList all tags
44git tag <name>Create a new tag
45Others.gitignoreA file placed in the repository to specify exclusion file patterns separated by new line
.git/config or ~/.gitconfigThe git configuration file for a specific repository or global configuration

Download Git Cheatsheet

Download the printable single-page Git cheatsheet in PDF format by clicking the below button.



Git Cheatsheet – Frequently Used Git Commands
Be The First

Join our list to get instant access to new articles and weekly newsletter.

Tagged on:         
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x