← Back to Notes

Common Git Commands

gitcommandsdevelopment

🔹 Creating & Switching Branches

Create a new branch and switch to it:

git checkout -b feature/new-feature

Switch to an existing branch:

git checkout main

Create a new branch from current branch:

git branch feature/new-feature
git checkout feature/new-feature

🔹 Staging & Committing

Add all files to staging:

git add .

Add specific files:

git add filename.txt

Commit with message:

git commit -m "Add new feature"

Add and commit in one command:

git commit -am "Quick commit"

🔹 Pushing & Pulling

Push to remote repository:

git push origin main

Push new branch to remote:

git push -u origin feature/new-feature

Pull latest changes:

git pull origin main

Fetch remote changes:

git fetch origin

🔹 Branch Management

List all branches:

git branch

List all branches (including remote):

git branch -a

Delete local branch:

git branch -d feature/old-feature

Delete remote branch:

git push origin --delete feature/old-feature

🔹 Status & History

Check repository status:

git status

View commit history:

git log

View commit history (one line):

git log --oneline

View changes in last commit:

git show

🔹 Merging & Rebasing

Merge branch into current:

git merge feature/new-feature

Rebase current branch:

git rebase main

Abort rebase:

git rebase --abort

🔹 Stashing

Stash current changes:

git stash

Stash with message:

git stash push -m "Work in progress"

List stashes:

git stash list

Apply last stash:

git stash pop

🔹 Useful Aliases

Quick status:

git st

Quick commit:

git ci

Quick checkout:

git co

Quick branch:

git br