Catalog / Git Cheatsheet
Git Cheatsheet
A concise reference for Git commands and concepts, ideal for quick lookups and reminders.
Basic Commands
Configuration
|
Sets the name you want attached to your commit transactions. |
|
Sets the email you want attached to your commit transactions. |
|
Lists all Git configuration settings. |
|
Sets VS Code as the default editor for Git (replace |
Starting a Repository
|
Initializes a new Git repository in the current directory. |
|
Clones an existing Git repository from a remote URL. |
Basic Workflow
|
Shows the status of the working directory and staging area. |
|
Adds a file to the staging area. |
|
Commits the staged changes with a descriptive message. |
|
Shows the commit history of the repository. |
Branching and Merging
Branch Management
|
Lists all local branches in the repository. |
|
Creates a new branch with the specified name. |
|
Switches to the specified branch. |
|
Deletes the specified branch (if it has been merged). |
|
Forces deletion of the specified branch, even if it hasn’t been merged. |
Merging Branches
|
Merges the specified branch into the current branch. |
|
Opens the configured merge tool to resolve merge conflicts. |
|
After resolving conflicts, commit the merged changes. |
Rebasing
|
Rebases the current branch onto the specified branch. |
|
Continues the rebasing process after resolving conflicts. |
|
Aborts the rebasing process and returns to the original branch state. |
Remote Repositories
Connecting to Remotes
|
Adds a remote repository with the specified name and URL. |
|
Lists all configured remote repositories with their URLs. |
|
Removes the specified remote repository. |
Pushing and Pulling
|
Pushes the local branch to the specified remote repository. |
|
Pulls changes from the specified remote branch and merges them into the current branch. |
|
Downloads objects and refs from another repository. |
Tracking Branches
|
Sets up a tracking connection between the local branch and the remote branch. Use |
|
Manually sets the upstream branch for a local branch. |
Undoing Changes
Modifying Commits
|
Amends the last commit with new staged changes and/or a new commit message. |
|
Unstages the last commit, keeping the changes in the working directory. |
Reverting Changes
|
Discards changes to a file in the working directory, reverting it to the last committed version. |
|
Creates a new commit that undoes the changes made in the specified commit. |
Resetting
|
Resets the staging area and working directory to the state of the specified commit, but leaves the changes in the working directory. |
|
Resets the staging area to the state of the specified commit, but leaves the changes in the working directory (default behavior). |
|
Resets the staging area and working directory to the state of the specified commit, discarding all changes. |