Fundamentals 10 min read

Common Git Commands Cheat Sheet

This guide presents a comprehensive collection of frequently used Git commands, covering repository setup, aliases, branching, committing, history inspection, undo operations, remote interactions, merging, rebasing, and archiving, all illustrated with clear examples and explanations for developers.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Common Git Commands Cheat Sheet

1. Common Git Commands

Basic operations for interacting with a Git repository:

$ git remote add origin [email protected]:yeszao/dofiler.git
# Configure remote repository
$ git pull origin master
# Download and fast‑forward merge
$ git push origin master
# Upload and fast‑forward merge
$ git fetch origin
# Fetch objects from remote
$ git branch
# List all branches
$ git checkout master
# Switch to master branch
$ git checkout -b dev
# Create and switch to a new branch named dev
$ git commit -m "first version"
# Commit changes
$ git status
# Show working tree status
$ git log
# Show commit history
$ git config --global core.editor vim
# Set default editor to vim
$ git config core.ignorecase false
# Make Git case‑sensitive
$ git config --global user.name "YOUR NAME"
# Set user name
$ git config --global user.email "YOUR EMAIL ADDRESS"
# Set user email

2. Aliases (git config alias)

$ git config --global alias.br="branch"
# Shortcut for "git branch"
$ git config --global alias.co="checkout"
# Shortcut for "git checkout"
$ git config --global alias.cb="checkout -b"
# Create and switch to a new branch
$ git config --global alias.cm="commit -m"
# Shortcut for committing with a message
$ git config --global alias.st="status"
# Shortcut for "git status"
$ git config --global alias.pullm="pull origin master"
# Pull from origin master
$ git config --global alias.pushm="push origin master"
# Push to origin master
$ git config --global alias.log="log --oneline --graph --decorate --color=always"
# One‑line colored log
$ git config --global alias.logg="log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative"
# Detailed graph log

3. Creating a Repository

$ git clone
# Clone a remote repository
$ git init
# Initialize a new local repository

4. Modifying and Committing

$ git status
# Show current status
$ git diff
# Show changes
$ git add .
# Stage all modified files
$ git add
# Stage a specific file
$ git mv
# Rename a file
$ git rm
# Delete a file
$ git rm --cached
# Stop tracking a file without deleting it
$ git commit -m "commit message"
# Commit all staged changes
$ git commit --amend
# Amend the most recent commit

5. Viewing History

$ git log
# Show full commit history
$ git log -p
# Show history for a specific file
$ git blame
# Annotate each line of a file with its commit

6. Undo Operations

$ git reset --hard HEAD
# Discard all uncommitted changes
$ git reset --hard
# Reset to a specific commit
$ git checkout HEAD --
# Discard changes in a specific file
$ git checkout --
# Same as above
$ git revert
# Revert a specific commit

7. Branches and Tags

$ git branch
# List local branches
$ git checkout
# Switch to a branch or tag
$ git branch -d
# Delete a local branch
$ git tag
# List tags
$ git tag
# Create a lightweight tag
$ git tag -a "v1.0" -m "release notes"
# Create an annotated tag
$ git tag -d
# Delete a tag
$ git checkout dev
# Switch to dev branch (often used before merging)
$ git cherry-pick 62ecb3
# Apply a specific commit

8. Merging and Rebasing

$ git merge
# Merge a branch into the current one
$ git merge --abort
# Abort an ongoing merge
$ git merge dev -Xtheirs
# Merge dev, preferring its changes on conflicts
$ git rebase
# Rebase current branch onto another

9. Remote Operations

$ git remote -v
# Show remote URLs
$ git remote show
# Show details of a remote
$ git remote add
# Add a new remote
$ git remote remove
# Remove a remote
$ git fetch
# Fetch objects from a remote
$ git pull
# Fetch and merge
$ git push
# Push a branch
$ git push
# Push a tag
$ git push --tags
# Push all tags

10. Archiving (Packaging)

$ git archive --format=zip --output ../file.zip master
# Create a zip archive of the master branch
$ git archive --format=zip --output ../v1.2.zip v1.2
# Archive the v1.2 tag

11. Global and Local Configuration

Global settings are stored in $HOME/.gitconfig , while repository‑specific settings reside in .git/config .

12. Quick Workflow Example

$ git init
$ git add .
$ git commit -m "add local source"
$ git pull origin master
$ git merge master
$ git push -u origin master

This sequence initializes a repository, adds files, commits, synchronizes with a remote, merges, and pushes the changes.

gitcommand lineVersion ControlRepositorybranchingmergingaliases
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.