Git is a Version Control System (VCS) that keeps track of all updates you make in a project.
It allows you to manage versions, collaborate with others, and revert to previous states safely.
When you initialize Git:
git init -b mainGit creates:
- Your working directory
- A hidden
.gitfolder (stores commit history & tracking info)
Git does not automatically track files.
You must add files to the staging area:
git add filename.extThen commit changes:
git commit -m "your message"View commit history:
git loggit config --global user.name "Your Name"
git config --global user.email "your@email.com"Add single file:
git add file.extAdd all files:
git add .Commit directly (skip manual staging for tracked files):
git commit -a -m "message"Check differences:
git diffRemove file from tracking:
git rm --cached file.extgit init
git add .
git commit -m "message"
git remote add origin https://github.com/username/repository.git
git branch -M main
git push -u origin mainTags are version names given to commits.
git tag
git tag -a v1.0 -m "Version 1.0"
git show v1.0
git push origin v1.0Switch branch:
git checkout branchname
# or
git switch branchnameCreate & switch to new branch:
git checkout -b branchname
# or
git switch -b branchnameView branches:
git branchDelete local branch:
git branch -d branchnameDelete remote branch:
git push origin --delete branchnamegit merge feature-branchgit rebase branchnameUse:
merge→ keep feature historyrebase→ clean linear history
Occurs when two branches modify the same line of code.
You must manually choose which changes to keep, then:
git add .
git commit -m "resolved conflict"Push (local → remote):
git push origin mainPull (remote → local):
git pull origin mainTemporarily save unfinished work:
git stash
git stash list
git stash applyFork creates a copy of someone else's repository into your GitHub account.
You can modify it freely and later create a Pull Request to contribute changes.
After pushing changes to your fork:
- Go to GitHub
- Click Pull Requests
- Select base repository
- Click Create Pull Request
Made with ❤️ while learning Git
