Git Cheat Sheet – Git Commands for Easy Reference
What Is Git?
Git is a Distributed Version Control System (DVCS) for saving different versions of a file (or set of files)—wherein any version is retrievable at will.
Git makes it easy to record and compare different file versions. Consequently, details about what changed, who changed what, or who initiated an issue are reviewable anytime.
Below are some of the widely used Git commands.
How to Install and Update Git
Below are the commands for installing and updating Git on your system.
Description | Command |
---|---|
Install Git | |
Check Git's installation location |
|
Check the installed Git version |
|
Update Git (Windows) |
|
Update Git (Mac) |
How to Initialize and Clone Git
Below are the commands for initializing new local Git repositories or cloning existing Git repositories.
Description | Command |
---|---|
Initialize Git |
|
Clone a Git repository |
|
How to Configure Git
Below are the commands for configuring, reviewing, and updating users' information for all local Git repositories.
Description | Command |
---|---|
Configure your Git username |
|
Configure your Git email |
|
Check your project's configurations |
|
Check your email configuration |
|
Check your username configuration |
|
Update your username configuration |
|
Update your email configuration |
|
Exit the Git configuration space | Press the Q keyboard key |
How to Track Changes
Below are the commands for monitoring changes to files or folders.
Description | Command |
---|---|
Check the status of your files |
|
Stage a specific file (or folder) |
note Replace |
Stage all modified and untracked files |
note The |
Stage the current directory's modified and untracked files |
note The dot symbol means "current directory." |
Stage all modified files that you've committed previously |
note The |
Compare the working directory and staging area's file versions |
|
Compare the staging area's file version with the most recently committed version |
|
How to Undo the Staging of files
Below are the commands for undoing the staging of files.
Description | Command |
---|---|
Undo the staging of a specific file |
|
Undo the staging of all files |
|
How to Commit Files to Git
Below are the commands for saving files to the Git repository.
Description | Command |
---|---|
Commit your files |
|
Stage and commit at once |
|
Commit without writing a commit message |
|
Modify a previous commit message | |
Commit without staging first |
|
Undo a specific commit |
note
|
How to View Your Commits
Below are the commands for viewing your commits.
Description | Command |
---|---|
See the changes you are about to commit |
|
View your project's commit history |
|
View a specific number of the project's commit history (for instance, the last three) |
|
Exit the Git console space | Press the Q keyboard key |
See all the files currently in the staging area and the Git repository |
|
Check if a specific file or folder is in the Git directory |
note Replace |
How to Ignore Files
Below are the commands for telling Git to ignore specific files.
Description | Command |
---|---|
Create a .gitignore file |
|
See an example of a .gitignore file | |
Open Gitignore's manual page |
note The Gitignore manual will open in your default browser. |
How to Manage Git Branches
Below are the commands for creating, renaming, deleting, and switching between Git branches.
Description | Command |
---|---|
Check your project's local branches |
note Git will mark the current branch with an asterisk ( |
Check your project's remote branches |
|
Create a new branch |
|
Delete a specific branch |
|
Rename your project's HEAD branch |
|
Rename a non-HEAD branch |
|
Switch from one branch to another |
|
Switch back to the previous branch |
|
Create and switch immediately to a new branch |
|
Switch to a specific commit history |
note A commit hash is a long string that follows the word "commit" in a |
Merge a specific branch into the HEAD branch |
important Before invoking the merge command, make sure the active branch is the branch you want to merge into. In other words, switch to the branch you wish to update before running the merge command. |
Compare branches |
|
How to Share Git Repos
Below are the commands for sharing content between local and remote Git repositories.
Description | Command |
---|---|
Link your project's local and remote repositories |
note Replace |
Confirm the connection between your local and remote repositories |
|
Push your local Git repo to the remote repository |
note
|
Confirm the upload of your local Git repo to the remote repository | Go to your GitHub repository page and refresh the browser. |
Undo the pushing of a commit upstream |
note
|
Publish your app on GitHub Pages |
How to Delete Files and Folders
Below are the commands for deleting files and folders from the working directory and Git repository.
Description | Command |
---|---|
Delete a file from the working directory and the Git repository |
|
Forcefully delete a file from the working directory and the Git repository |
|
Delete a folder from the working directory and the Git repository |
|
Delete a file only from the staging area—not from the working directory |
|
Rename a specific file |
|
Replace a working directory's file with its last committed version |
|
Get your free PDF Git cheat sheet.
Use it to easily remember the Git commands you need for your projects.