Git Cheat Sheet

In Git, Prompts

If you’re new to Git or need a quick reference guide, this cheat sheet provides an extensive list of Git commands organized by category. Whether you’re just starting out or are a seasoned Git user, this cheat sheet is a handy resource for everyday Git use.

The cheat sheet includes commands for setting up a repository, staging changes, committing changes, viewing changes and history, branching and merging, working with remote repositories, stashing changes, managing tags, configuring Git, and other miscellaneous commands.

To use this cheat sheet, simply find the category of command you’re looking for, and then locate the specific command you need. The cheat sheet provides a brief description of each command, along with its syntax and any options or arguments that can be used.

Whether you’re a beginner or an experienced Git user, this cheat sheet is a valuable resource for anyone working with Git on a regular basis. Use it as a quick reference guide, or print it out and keep it nearby for easy access.

Cheat Sheet

Repository Setup

Git CommandDescription
git initInitialize a new Git repository
git clone [url]Clone an existing Git repository
git remote add [remote_name] [url]Add a new remote repository

Staging Changes

Git CommandDescription
git add [file]Add a file or files to the staging area
git add .Add all changes to the staging area
git reset [file]Remove a file from the staging area

Committing Changes

Git CommandDescription
git commit -m “[message]”Commit changes to the repository
git commit -a -m “[message]”Commit all changes (including deleted files) to the repository
git commit –amendAmend the last commit with new changes

Viewing Changes

Git CommandDescription
git statusShow the status of the repository
git diffShow the differences between the working directory and the staging area
git diff –stagedShow the differences between the staging area and the repository

Viewing History

Git CommandDescription
git logShow the commit history
git log –graph –oneline –decorate –allShow a graph of the commit history

Branching and Merging

Git CommandDescription
git branchList all branches in the repository
git branch [branch_name]Create a new branch
git checkout [branch_name]Switch to a different branch
git merge [branch_name]Merge the specified branch into the current branch
git rebase [branch_name]Rebase the current branch on top of another branch
git cherry-pick [commit_hash]Apply a specific commit from another branch
git branch -d [branch_name]Delete a branch

Remote Repositories

Git CommandDescription
git push [remote_name] [branch_name]Push the current branch to a remote repository
git pull [remote_name] [branch_name]Pull changes from a remote repository
git fetch [remote_name]Fetch changes from a remote repository
git remote show [remote_name]Show information about a remote repository
git remote remove [remote_name]Remove a remote repository

Stashing Changes

Git CommandDescription
git stashStash changes in a dirty working directory
git stash listList stashed changes
git stash applyApply the most recent stash
git stash apply [stash_name]Apply a specific stash

Tags

Git CommandDescription
git tag [tag_name]Create a new tag at the current commit
git tag -a [tag_name] -m “[message]”Create an annotated tag with a message
git push [remote_name] –tagsPush all tags to a remote repository

Configuration

Git CommandDescription
git config –global user.name “[name]”Set the name associated with Git commits
git config –global user.email “[email]”Set the email associated with Git commits
git config –global core.editor “[editor]”Set the text editor used by Git
git config –global color.ui autoEnable colored output for Git commands

Miscellaneous

Git CommandDescription
git rm [file]Remove a file from the repository
git mv [old_file] [new_file]Rename a file in the repository
git blame [file]Show the author and last modified time of each line in a file
git grep [pattern]Search for a pattern in the repository
git archive [branch_name] –format=[format] –output=[output_file]Create an archive of a branch in a specified format

Reference:

https://git-scm.com/docs/git