Git & GitHub Complete Notes
1. What is Git?
Git is a version control system used to track changes in files and coordinate work among
developers.
It allows you to:
- Revert to previous versions
- Work in branches
- Collaborate with others
2. Basic Git Commands
Initialize a Git repo:
git init
Check status of files:
git status
Stage a file for commit:
git add <file>
Commit changes with message:
git commit -m "Initial commit"
See commit history:
git log
Compare file changes:
git diff
3. Branching in Git
Create a new branch:
git branch new-feature
Switch to another branch:
git checkout new-feature
Merge a branch:
git merge new-feature
4. Remote Repositories
Clone a repository from GitHub:
git clone [Link]
Add a remote origin:
git remote add origin [Link]
Push changes to GitHub:
git push -u origin main
Pull updates from GitHub:
git pull
5. What is GitHub?
GitHub is a platform that hosts Git repositories online.
Key features:
- Repositories: Projects
- Forks: Create copies of projects
- Pull Requests: Propose changes
- Issues: Track tasks/bugs
6. GitHub Collaboration Flow
1. Clone repo
2. Create a branch
3. Make changes
4. Push branch
5. Create a pull request
6. Merge after approval
7. SSH vs HTTPS
- HTTPS: Simple, but asks for credentials every time unless cached
- SSH: Secure and easier once set up
Setup SSH with: ssh-keygen and add key to GitHub
8. Example Git Workflow
git init
git add .
git commit -m "initial commit"
git remote add origin <your-repo-url>
git push -u origin main
9. Branching Strategy
- main: Stable release
- develop: Integration branch
- feature/*: New features
- fix/*: Bug fixes