Introduction π
Git is the most widely used version control system in the world. It helps developers track code changes, collaborate with others, roll back mistakes, and manage project history efficiently.
Note
π‘ Fast, secure, reliable
π‘ Essential skill for every developer and team
1. Install Git π οΈ
- Windows β Download Git
- Linux β sudo apt install git
- Mac β brew install git
2. Configure Git (Important!) βοΈ
git_config.sh
git config --global user.name "Your Name"
git config --global user.email "you@example.com"β Identifies you in every commit
3. Initialize a Repository π
git_init.sh
git initβ Creates a hidden .git folder
β Starts tracking your project
4. Check Repository Status π
git_status.sh
git status5. Adding Files to Staging Area β
git_add.sh
git add file.py # single file
git add . # all files6. Commit Changes π
git_commit.sh
git commit -m "Initial commit"β Saves snapshot of your project
7. Viewing Commit History π
git_log.sh
git log8. Connecting to GitHub π
github_remote.sh
git remote add origin https://github.com/username/repo.git
git branch -M main
git push -u origin mainβ Pushes your local code β GitHub
9. Cloning Repositories π§©
git_clone.sh
git clone https://github.com/user/repo.git10. Branching πΏ
Branches allow you to work on features without affecting main code.
git_branch.sh
git branch # list branches
git branch feature-login # create branch
git checkout feature-login # switch branch11. Merging Branches π
git_merge.sh
git checkout main
git merge feature-loginβ Integrates feature branch into main
12. Handling Merge Conflicts β οΈ
If two branches edit the same lines, Git asks you to resolve conflicts manually.
Code Snippet
<<<<<<< HEAD <br/>
Your changes <br/>
======= <br/>
Their changes <br/>
>>>>>>> branch13. Git Ignore β Ignoring Files π«
gitignore.txt
__pycache__/
*.log
.env
node_modules/β Prevents unwanted files from being tracked
14. Undoing Changes π
Undo file modifications
git_restore.sh
git restore file.pyUnstage a file
git_reset.sh
git restore --staged file.pyUndo last commit
git_reset_commit.sh
git reset --soft HEAD~1 # keep changes
git reset --hard HEAD~1 # delete changesNote
15. Working with Remote Repos π
Pull new changes
git_pull.sh
git pull origin mainPush your changes
git_push.sh
git push origin main16. Stashing Work π¦
git_stash.sh
git stash # store current changes
git stash pop # apply changes backβ Useful when switching branches temporarily
17. Tagging Versions π·οΈ
git_tag.sh
git tag v1.0
git push origin v1.018. GitHub Pull Requests π§
PRs allow code review before merging changes.
- 1. Push feature branch
- 2. Open GitHub β Create Pull Request
- 3. Reviewer checks & approves
- 4. Merge into main
Git Cheat Sheet π
| Action | Git Command |
|---|---|
| Init repo | git init |
| Add files | git add . |
| Commit | git commit -m "" |
| Create branch | git branch new |
| Switch branch | git checkout new |
| Merge | git merge new |
| Push | git push |
| Pull | git pull |
| Tags | git tag |
Best Practices π‘
- β Commit small & meaningful changes
- β Write clear commit messages
- β Use branches for features/bugs
- β Never commit secrets (.env files)
- β Pull before pushing
- β Use PRs for team collaboration
Conclusion π
You now understand Git Version Control! Want the next topic? Try GitHub, Git Branching Strategies, CI/CD Pipelines, or Docker. Just tell me! π