DEV Community

Vishal Kondi
Vishal Kondi

Posted on

🧠 Ultimate Git Cheat Sheet for Developers πŸš€

yum install git -y # Install Git on Linux
git config user.name "Your Name" # Set Git username
git config user.email "your@email.com" # Set Git email
git init # Initialize Git in current folder

git add filename # Track specific file
git add . # Track all files (incl. hidden)
git commit -m "message" # Commit with message
git commit --amend -m "new msg" # Amend last commit message

git log # Full history
git log --oneline # Short history
git show # Show details of a commit

git reset --hard HEAD~1 # Remove last commit + changes
git reset --soft HEAD~1 # Remove last commit only
git revert # Revert specific commit

git branch # List branches
git branch # Create new branch
git checkout # Switch branch
git checkout -b # Create and switch branch
git merge # Merge branches
git cherry-pick # Pick specific commit

git remote add origin # Link to GitHub repo
git push -u origin # Push code to GitHub
git clone # Clone remote repo
git pull origin # Pull latest changes

git stash # Stash current changes
git stash apply # Apply stashed changes
git stash list # List all stashes
git stash drop stash@{0} # Remove specific stash

git branch -d # Delete branch
git push origin --delete # Delete remote branch
git remote rm origin # Unlink remote

Top comments (0)