Complete Git & GitHub Notes for Team Collaboration
What is Git?
Git is a Version Control System (VCS) used to track changes in code, files, and projects over time.
It helps developers:
- Track changes
- Collaborate with teams
- Restore previous versions
- Manage projects efficiently
What is GitHub?
GitHub is a cloud platform used to store and manage code repositories online.
Github Link:
https://github.com
1. Git Configuration
Set username:
git config --global user.name "Your Name"
Set email:
git config --global user.email "youremail@domain.com"
Check configuration:
git config --list
Help command:
git help
2. Create or Clone Repository
Initialize a new repository:
git init
Clone a repository:
git clone https://github.com/username/project.git
3. Staging and Committing
Add a file:
git add filename
Add all files:
git add .
Commit changes:
git commit -m "Your commit message"
4. Daily Git Workflow (Most Important)
Check status:
git status
Add changes:
git add .
Commit changes:
git commit -m "Updated project"
Push to GitHub:
git push
First time push:
git push -u origin main
5. Complete First-Time GitHub Upload
git init
git add .
git commit -m "First commit"
git branch -M main
git remote add origin https://github.com/username/repository.git
git push -u origin main
6. Branching in Git
Create branch:
git branch branchname
Switch branch:
git checkout branchname
Create and switch:
git checkout -b branchname
List branches:
git branch
Merge branch:
git merge branchname
Delete branch:
git branch -d branchname
7. Team Branch Workflow (Very Important)
Project Branch Structure:
main
dev
person1-data
person2-preprocessing
person3-model
Team Members
| Person | Responsibility | Branch |
|---|---|---|
| Subin | Data Cleaning & EDA | person1-data |
| Bibek | Feature Engineering | person2-preprocessing |
| Sachin | Model Training & Evaluation | person3-model |
Workflow Concept
main = final project
dev = testing branch
person branches = personal workspaces
Nobody works directly on main.
8. Create Team Branches
Create dev branch:
git checkout -b dev
git push -u origin dev
Create Person 1 branch:
git checkout -b person1-data
git push -u origin person1-data
Create Person 2 branch:
git checkout dev
git checkout -b person2-preprocessing
git push -u origin person2-preprocessing
Create Person 3 branch:
git checkout dev
git checkout -b person3-model
git push -u origin person3-model
9. How Team Members Work
Subin
Switch branch:
git checkout person1-data
After work:
git add .
git commit -m "EDA completed"
git push
Bibek
git checkout person2-preprocessing
After work:
git add .
git commit -m "TF-IDF preprocessing completed"
git push
Sachin
git checkout person3-model
After work:
git add .
git commit -m "Naive Bayes model completed"
git push
10. How Merging Works
Example:
person1-data → dev
After merge:
dev updated
Then Bibek updates latest code:
git checkout dev
git pull origin dev
Then move changes into his branch:
git checkout person2-preprocessing
git merge dev
Now Bibek has latest cleaned dataset.
11. Remote Repository Commands
Add remote:
git remote add origin https://github.com/username/repository.git
View remote:
git remote -v
Show remote details:
git remote show origin
Push code:
git push origin main
Pull updates:
git pull
12. File Management
Remove file:
git rm filename
Rename file:
git mv oldname newname
13. History & Logs
View changes:
git diff
View commit history:
git log
Short log:
git log --oneline
14. Tags (Version Control)
Create tag:
git tag v1.0
Push tag:
git push origin v1.0
Push all tags:
git push origin --tags
Delete local tag:
git tag -d v1.0
Delete remote tag:
git push origin :refs/tags/v1.0
15. Undo Mistakes
Undo last commit (keep changes):
git reset --soft HEAD~1
Undo last commit completely:
git reset --hard HEAD~1
Restore file:
git restore filename
16. Ignore Files (.gitignore)
node_modules/
.env
__pycache__/
17. Most Important Git Commands
git init
git clone
git status
git add .
git commit -m "message"
git push
git pull
git branch
git checkout
git merge
git log
18. Pro Tips
Good commit message:
git commit -m "Added login authentication system"
Bad commit message:
git commit -m "update"
19. Simple Git Flow (Easy Memory)
git add → stage changes
git commit → save changes
git push → upload to GitHub
20. Final Advice
- Commit small changes regularly
- Write meaningful messages
- Push code often
- Pull latest updates before working
- Never work directly on
main - Practice Git daily
Final Workflow Diagram
main ↑ dev ↑ person1-data person2-preprocessing person3-model