Initialize, clone, and configure Git repositories
git init
git clone https://github.com/username/repository.git
git clone https://github.com/username/repository.git my-folder
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --list
Track changes, stage files, and create commits
git status
git add .
git add filename.txt
git commit -m "Add new feature"
git log
git log --oneline
git diff
git diff --staged
Create, switch, and merge branches
git branch
git branch main
git checkout main
git switch main
git checkout -b feature-branch
git merge main
git branch -d feature-branch
git branch -D feature-branch
Connect and sync with remote repositories
git remote -v
git remote add origin https://github.com/username/repository.git
git push origin main
git push -u origin main
git pull origin main
git fetch origin
git remote remove origin
git remote set-url origin https://github.com/username/new-repository.git
Undo changes, reset commits, and manage stashes
git reset --soft HEAD~1
git reset --mixed HEAD~1
git reset --hard HEAD~1
git reset --hard abc1234
git revert abc1234
git stash
git stash pop
git stash list
git stash drop
git rebase main
git rebase -i HEAD~3
Advanced Git operations for power users
git reflog
git tag v1.0.0
git tag -l
git cherry-pick abc1234
git commit --amend -m "Updated commit message"
git rebase -i abc1234
Git is a distributed version control system designed to track changes in source code during software development. It was created by Linus Torvalds in 2005 for development of the Linux kernel. Git allows multiple developers to work together on the same project, track changes, and maintain a complete history of modifications. It's essential for modern software development and is used by millions of developers worldwide.
git push {remote} {branch}
becomes git push origin main
when you enter "origin" and "main" in the respective fields.git status
- Check current stategit add .
- Stage changesgit commit -m "message"
- Commit changesgit push
- Upload to remotegit checkout -b feature
- Create feature branchgit push -u origin feature
- Push feature branchgit status
frequently to understand your current stategit log --oneline
for a compact view of commit historygit pull
before starting new work to get latest changesgit stash
to temporarily save work when switching branchesgit reflog
is your safety net - it can recover almost anythinggit reset --hard
permanently deletes changes - use with caution