A collection of essential Git commands for managing your code repositories efficiently.
Check current configuration:
git config --list
Set username and email:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Initialize a new repository:
git init
Clone an existing repository:
git clone [repository-url]
Check current status:
git status
Stage changes:
git add [file]
Stage all changes:
git add .
Commit changes:
git commit -m "Your commit message"
Unstage a file:
git reset [file]
List branches:
git branch
Create a new branch:
git checkout -b [branch-name]
Switch branches:
git checkout [branch-name]
Delete a branch:
git branch -d [branch-name]
Merge a branch:
git merge [branch-name]
Rebase current branch:
git rebase [branch-name]
Add a remote repository:
git remote add origin [url]
Push changes to remote:
git push origin [branch-name]
Pull latest changes:
git pull origin [branch-name]
Discard local changes:
git checkout -- [file]
Revert a commit:
git revert [commit-id]
Reset to a previous commit:
git reset --hard [commit-id]
View commit history:
git log
View a summarized log:
git log --oneline
Show changes for a file:
git diff [file]
📚 Official Git Documentation
For more in-depth information, visit: https://git-scm.com/doc