This content originally appeared on DEV Community and was authored by IJAS AHAMMED
A quick reference for the most common and useful Git commands.
đź› Setup & Initialization
Command | Description |
---|---|
git init |
Initialize a new Git repository in the current directory. |
git clone [repo-url] |
Clone an existing repository. |
git remote -v |
List remote repositories connected to your project. |
git remote add origin [url] |
Link a local repo to a remote repo. |
git branch -M [new-name] |
Rename the current branch (commonly main ). |
đź“‚ Working with Files
Command | Description |
---|---|
git add [file/dir] |
Stage a file or directory for commit. |
git add . |
Stage all changes in the current directory. |
git rm [file] |
Remove a file and stage the removal. |
git mv [old] [new] |
Rename or move a file. |
đź’ľ Saving Changes
Command | Description |
---|---|
git commit -m "msg" |
Commit staged changes with a message. |
git commit -am "msg" |
Stage and commit tracked files in one step. |
git reset --soft [hash] |
Undo commits but keep changes staged. |
git reset [hash] |
Undo commits and unstage changes (keep in working dir). |
git reset --hard [hash] |
Reset everything to a specific commit (âš destructive). |
git revert [hash] |
Create a new commit that undoes a specific commit. |
git revert --continue |
Continue revert if conflicts occur. |
git revert --abort |
Cancel an in-progress revert. |
🌿 Branching & Merging
Command | Description |
---|---|
git branch |
List all branches, * shows current branch. |
git branch [name] |
Create a new branch. |
git branch [new] [existing] |
Create new branch from another. |
git checkout [branch] |
Switch to an existing branch. |
git checkout -b [name] |
Create and switch to a new branch. |
git merge [branch] |
Merge a branch into the current branch. |
git push --set-upstream origin [branch] |
Push new branch and set remote tracking. |
🔄 Sync with Remote
Command | Description |
---|---|
git pull |
Fetch and merge from remote. |
git fetch |
Download changes but don’t merge yet. |
git push |
Push commits to remote. |
git push -u origin main |
Push and set default upstream (first push). |
📊 Check Status & History
Command | Description |
---|---|
git status |
Show staged/unstaged/untracked files. |
git log |
Show commit history. |
git log --oneline --graph --decorate --all |
Pretty, compact commit history. |
git diff [file] |
Show unstaged changes for a file. |
git diff --staged |
Show staged changes (ready to commit). |
đź—„ Stash & Temporary Work
Command | Description |
---|---|
git stash |
Save uncommitted changes temporarily. |
git stash list |
Show list of stashed changes. |
git stash apply [id] |
Apply stashed changes (keeps in stash). |
git stash pop |
Apply and remove from stash. |
⚔️ Resolving Merge Conflicts
git checkout main
git pull origin main
git checkout your-branch
git merge main
# Resolve conflicts manually in files
git add .
git commit -m "fix merge conflict"
git push
This content originally appeared on DEV Community and was authored by IJAS AHAMMED
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.

APA
MLA
IJAS AHAMMED | Sciencx (2025-09-28T02:48:24+00:00) Git Cheatsheet. Retrieved from https://www.scien.cx/2025/09/28/git-cheatsheet-7/
" » Git Cheatsheet." IJAS AHAMMED | Sciencx - Sunday September 28, 2025, https://www.scien.cx/2025/09/28/git-cheatsheet-7/
HARVARDIJAS AHAMMED | Sciencx Sunday September 28, 2025 » Git Cheatsheet., viewed ,<https://www.scien.cx/2025/09/28/git-cheatsheet-7/>
VANCOUVERIJAS AHAMMED | Sciencx - » Git Cheatsheet. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/28/git-cheatsheet-7/
CHICAGO" » Git Cheatsheet." IJAS AHAMMED | Sciencx - Accessed . https://www.scien.cx/2025/09/28/git-cheatsheet-7/
IEEE" » Git Cheatsheet." IJAS AHAMMED | Sciencx [Online]. Available: https://www.scien.cx/2025/09/28/git-cheatsheet-7/. [Accessed: ]
rf:citation » Git Cheatsheet | IJAS AHAMMED | Sciencx | https://www.scien.cx/2025/09/28/git-cheatsheet-7/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.