🏠 Home›Cheatsheets›Git

💻 Git Cheatsheet

Common git commands and workflows

Initialize Repository

Create a new git repository

git init

Clone Repository

Clone an existing repository

git clone <url>

Check Status

Show working tree status

git status

Add Files

Stage files for commit

git add . git add <file>

Commit Changes

Commit staged changes

git commit -m "message" git commit -am "message"

View History

Show commit history

git log git log --oneline git log --graph --all

Create Branch

Create and switch to new branch

git branch <branch-name> git checkout -b <branch-name> git switch -c <branch-name>

Switch Branch

Switch to different branch

git checkout <branch-name> git switch <branch-name>

List Branches

Show all branches

git branch git branch -a

Delete Branch

Delete a branch

git branch -d <branch-name> git branch -D <branch-name>

Merge Branch

Merge branch into current branch

git merge <branch-name>

Rebase Branch

Rebase current branch

git rebase <branch-name>

Push Changes

Push commits to remote

git push git push origin <branch-name> git push -u origin <branch-name>

Pull Changes

Fetch and merge from remote

git pull git pull origin <branch-name>

Fetch Changes

Fetch from remote without merging

git fetch git fetch origin

Stash Changes

Temporarily save uncommitted changes

git stash git stash pop git stash list

Undo Last Commit

Undo last commit (keep changes)

git reset --soft HEAD~1

Amend Commit

Modify last commit

git commit --amend

View Diff

Show changes

git diff git diff --staged git diff <branch1> <branch2>

Tag Release

Create version tag

git tag <tag-name> git tag -a <tag-name> -m "message" git push origin <tag-name>

More in this category

|🏠 Home|
|