Git Cheat Sheet

git cheat sheet

Git is an incredibly powerful tool for version control and collaborative software development. However, mastering Git can be a daunting task, with its many commands and complex workflows. That’s where a Git cheat sheet comes in handy. A Git cheat sheet is a quick reference guide that lists all the essential Git commands and shortcuts in one place, making it easier for beginners and pros alike to navigate Git with ease. In this tutorial, we’ll provide a detailed Git cheat sheet that covers all the essential Git commands and categories, from basic repository setup to advanced branching and merging. So, whether you’re new to Git or a seasoned pro, this Git cheat sheet is sure to be a valuable resource in your arsenal.

Repository Creation and Cloning

Git CommandDescription
git initInitializes a new Git repository
git clone <url>Clones a repository from a URL

Branching

Git CommandDescription
git branchLists all local branches
git branch <name>Creates a new branch
git checkout <branch>Switches to a branch
git merge <branch>Merges a branch into the current branch
git branch -d <branch>Deletes a branch

Staging Changes

Git CommandDescription
git add <file>Adds changes to the staging area
git add .Adds all changes to the staging area
git reset <file>Removes changes from the staging area
git reset --hardDiscards all local changes

Committing Changes

Git CommandDescription
git commit -m "<message>"Commits changes with a message
git commit -a -m "<message>"Commits all changes with a message
git commit --amendChanges the last commit

Viewing Changes

Git CommandDescription
git statusShows the status of the working tree
git logShows the commit history
git diff <file>Shows the differences between files
git diff --stagedShows the differences between staged and committed files

Remote Repositories

Git CommandDescription
git remote add <name> <url>Adds a remote repository
git push <remote> <branch>Pushes changes to a remote repository
git pull <remote> <branch>Pulls changes from a remote repository
git fetch <remote>Fetches changes from a remote repository

Stashing Changes

Git CommandDescription
git stashStashes changes in the working directory
git stash listLists all stashes
git stash apply <stash>Applies a stash
git stash drop <stash>Deletes a stash

Miscellaneous

Git CommandDescription
git config --global user.name "<name>"Sets the user name for all repositories
git config --global user.email "<email>"Sets the email for all repositories
git rm <file>Removes a file
git mv <oldname> <newname>Renames a file
git tag <name>Creates a new tag
git tagLists all tags
git tag -d <name>Deletes a tag
Follow us on social media
Follow Author