Top Git Commands Every Developer Should Know
khaled-17
Posted on February 11, 2024
Initialize a Repository:
git init
Clone a Repository:
git clone <repository_url>
Check Repository Status:
git status
Stage Changes:
git add <file_name>
Commit Changes:
git commit -m "Your commit message"
View Commit History:
git log
Create a New Branch:
git branch <branch_name>
Switch to a Branch:
git checkout <branch_name>
Merge Branches:
git merge <branch_name>
Pull Changes from a Remote Repository:
bash
git pull origin <branch_name>
Push Changes to a Remote Repository:
bash
git push origin <branch_name>
Check Differences between Branches:
bash
git diff <branch1> <branch2>
Discard Changes in Working Directory:
bash
git checkout -- <file_name>
Undo the Last Commit (Keep Changes):
bash
git reset --soft HEAD^
Undo the Last Commit (Discard Changes):
bash
git reset --hard HEAD^
Stash Changes:
bash
git stash
Apply Stashed Changes:
bash
git stash apply
Create a Tag:
bash
git tag -a <tag_name> -m "Your tag message"
Fetch Changes from a Remote Repository:
bash
git fetch origin
Remove Untracked Files:
bash
git clean -fd
Posted on February 11, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.