Git command cheatsheet
This Git command cheatsheet includes commonly used commands for setting up a repository, committing changes, working with branches, publishing changes, and inspecting changes. It also includes miscellaneous commands such as stashing and tagging.
Note: The commands are described in brief and can be helpful for Git users of all levels.
Git Initialization
This command will Initialize a new Git repository in the current directory
Show Branches
Show a list of all local branches.
Create new branch
Create a new branch with the given name.
Delete a branch
This command will delete your provided branch.
List all branches
git branch -a command is used to list all branches in a Git repository, including both local and remote branches
Checkout branch
Switch to the specified existing branch by their name.
Create and checkout a new branch
Using this single command you can create a new branch and switch to it.
Merge branch
Merge the specified branch into the current branch.
Abort a merge
Abort a merged branch that has conflicts.
Push commit
Push committed changes to a remote repository.
Push Branch
Push changes to a specific branch on a remote repository.
Clone a repository
This will create a clone or copy inside a folder of a remote repository in your local machine.
Pull
Pull the latest changes from a remote repository.
Pull rebase
Pull changes from a remote repository and rebase instead of merging.
Fetch
Fetch the latest changes from a remote repository without merging them into your local branches.
Merge remote branch into a local branch
Merge changes from a remote branch into your current local branch.
Add a new remote repository to track
Show list of branches
Show a list of all remote repositories being tracked.
Show commit history
Show the commit history for the current branch.
Show the commit history for a specific file
Commit history with a graph of the branch
Show the commit history with a graph of branch and merge information.
Show the changes made to files that have been staged but not yet committed.
Git diff is commonly used to compare branches in a repository. It displays removed, added, and changed lines in the original file.
Add a single file
Stage changes to a file to be committed in git.
Show the changes made to files in the given commit.
Show the changes made between two commits
Show the status of the current branch and staged changes.
Stash changes are to be reapplied later
Reapply the most recently stashed changes
Create a new tag at the specified commit
Show a list of all tags in the repository.
Change the URL of the existing remote repository
This command is used to change the URL of an existing Git remote repository. This command is useful when you need to update the URL of a remote repository.
Add or commit all files
Stage all changed files or new files in the current directory to be committed
Reset file
Unstaged changes to a file from commit.
Reset all files
Unstage all changes from commit.
Commit changes with a message
Commit staged changes with a brief message describing the changes made in the local working branch.
Commit all changes
Stage and commit all changes in one command.
Modify recent commit message
This command will help to modify the most recent commit message.