Git and Git Flow Cheatsheet
Version Control
Essential Tool
Git is the most popular distributed version control system used by developers worldwide. This comprehensive cheatsheet covers all essential Git commands and Git Flow workflow to help you master version control.
Quick Reference
Most Used Commands
Day-to-day commands for tracking changes.
Emergency Commands
Quickly undo mistakes and save work.
Setup
Configuration Commands
Show current configuration
Show repository configuration
Show global configuration
Show system configuration
Set user name
Set user email
Set automatic command line coloring
Set global editor for commit
Configuration Files
Repository specific configuration file [--local]
User-specific configuration file [--global]
System-wide configuration file [--system]
Create
Repository Creation
Clone repository via SSH
Clone repository via HTTP
Create new local repository
Create new repository in directory
Local Changes
Status and Differences
Changes in working directory
Changes to tracked files
See changes/difference of a specific file
Adding Changes
Add all current changes to the next commit
Add some changes in <file>
to the next commit
Add only the mentioned files to the next commit
Committing Changes
Commit all local changes in tracked files
Commit previously staged changes
Commit with message
Commit skipping staging area
Commit to some previous date
Change last commit
Don't amend published commits!
Amend with previous commit message
Don't amend published commits!
Change committer date of last commit
Change Author date of last commit
Stashing
Move uncommitted changes to another branch
Restore stashed changes back to current branch
Restore particular stash back to current branch
{stash_number}
can be obtained from git stash list
Remove the last set of stashed changes
Search
Text Search
A text search on all files in the directory
In any version of a text search
Show commits that introduced a specific keyword
Show commits with keyword (regex)
Commit History
Viewing History
Show all commits, starting with newest
Show commits (hash and message only)
Show all commits of a specific user
Show changes over time for a specific file
Display commits in remote/branch comparison
Who changed, what and when in <file>
Show Reference log
Delete Reference log
Move / Rename
File Operations
Rename a file (Rename Index.txt to Index.html)
Branches & Tags
Branch Management
List all local branches
List local/remote branches
List all remote branches
Switch HEAD branch
Checkout single file from different branch
Create and switch new branch
Switch to previous branch
Create new branch from existing branch
Create new branch from existing commit
Create a new branch based on your current HEAD
Create new tracking branch from remote
Delete a local branch
Rename current branch to new branch name
Force delete a local branch
You will lose unmerged changes!
Apply specific commit from another branch
Tag Management
Mark HEAD
with a tag
Mark HEAD
with tag and message
Mark HEAD
with tag that includes a message
List all tags
List all tags with their messages
Update & Publish
Remote Management
List all current configured remotes
Show information about a remote
Add new remote repository, named <remote>
Rename remote repository
Remove a remote
git remote rm
does not delete the remote repository from the server. It simply removes the remote and its references from your local repository.
Fetching and Pulling
Download changes without integrating
Download changes and merge into HEAD
Get all changes from HEAD to local repository
Get changes without merge
Pushing
Publish local changes on a remote
Delete a branch on the remote (since Git v1.5.0)
Delete a branch on the remote (since Git v1.7.0)
Publish your tags
Merge Tools
Configure merge tool globally
Use configured merge tool to solve conflicts
Merge & Rebase
Merging
Merge branch into your current HEAD
List merged branches
Rebasing
Rebase current HEAD onto <branch>
Don't rebase published commit!
Abort a rebase
Continue a rebase after resolving conflicts
Mark file as resolved
Remove resolved file
Squashing commits
Now replace this:
to this:
Undo
Reset Operations
Discard all local changes
Undo last git add
Discard local changes in a specific file
Revert a commit (by producing a new commit with contrary changes)
Reset HEAD and discard all changes
Reset HEAD to remote branch state
Reset HEAD and preserve unstaged changes
Reset HEAD and preserve local changes
Remove accidentally committed files
Git Flow
Improved Git-flow workflow for better branch management.
Installation
OSX Homebrew
OSX Macports
Linux (Debian-based)
Windows (Cygwin)
You need wget and util-linux to install git-flow.
Getting Started
Git flow needs to be initialized in order to customize your project setup. Start using git-flow by initializing it inside an existing git repository:
Initialize with questions
Initialize with default values
Features
Develop new features for upcoming releases. Typically exist in developers repos only.
Start a new feature
This action creates a new feature branch based on 'develop' and switches to it.
Finish up a feature
Finish the development of a feature. This action:
- Merges MYFEATURE into 'develop'
- Removes the feature branch
- Switches back to 'develop' branch
Publish a feature
Are you developing a feature in collaboration? Publish a feature to the remote server so it can be used by other users.
Get a published feature
Get a feature published by another user.
Track a origin feature
You can track a feature on origin by using
Make a Release
Support preparation of a new production release. Allow for minor bug fixes and preparing meta-data for a release.
Start a release
To start a release, use the git flow release command. It creates a release branch created from the 'develop' branch.
Publish the release branch
It's wise to publish the release branch after creating it to allow release commits by other developers.
Track a remote release
Finish up a release
Finishing a release performs several actions:
- Merges the release branch back into 'master'
- Tags the release with its name
- Back-merges the release into 'develop'
- Removes the release branch
Don't forget to push your tags with git push --tags
Hotfixes
Hotfixes arise from the necessity to act immediately upon an undesired state of a live production version. May be branched off from the corresponding tag on the master branch that marks the production version.
Start a hotfix
Like the other git flow commands, a hotfix is started with
Finish a hotfix
By finishing a hotfix it gets merged back into develop and master. Additionally the master merge is tagged with the hotfix version
Git Flow Workflow Visualization
The Git Flow workflow provides a robust framework for managing releases and features:
- Master branch: Production-ready code
- Develop branch: Integration branch for features
- Feature branches: New feature development
- Release branches: Prepare for production release
- Hotfix branches: Quick fixes for production issues
Git Flow is excellent for teams with scheduled releases, but consider GitHub Flow or GitLab Flow for continuous deployment workflows.
Best Practices
Follow these Git best practices for better collaboration and code management.
- Write meaningful commit messages - Use conventional commits format
- Use branches for features - Keep master/main clean
- Review code before merging - Use pull/merge requests
- Keep commits atomic - One logical change per commit
- Test before pushing - Ensure code works locally
- Use .gitignore - Don't commit build artifacts or sensitive files
Learn More
Explore comprehensive Git documentation
Resources
Written by
Deepak Jangra
Created At
Thu Jun 12 2025
Updated At
Fri Jun 13 2025