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.
|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.
|Clone a Git repository|
How to Configure Git
Below are the commands for configuring, reviewing, and updating users' information for all local Git repositories.
|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.
|Check the status of your files|
|Stage a specific file (or folder)|
Stage all modified and untracked files
|Stage the current directory's modified and untracked files|
The dot symbol means "current directory."
|Stage all modified files that you've committed previously|
|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.
|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.
|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|
How to View Your Commits
Below are the commands for viewing your commits.
|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|
|Check if a specific file or folder is in the Git directory|
How to Ignore Files
Below are the commands for telling Git to ignore specific files.
|Create a |
|See an example of a |
|Open Gitignore's manual page|
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.
Check your project's local branches
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|
A commit hash is a long string that follows the word "commit" in a
Merge a specific branch into the HEAD branch
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.
How to Share Git Repos
Below are the commands for sharing content between local and remote Git repositories.
|Link your project's local and remote repositories|
|Confirm the connection between your local and remote repositories|
|Push your local Git repo to the remote repository|
|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|
|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.
|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|