Git and GitHub Summary
Version Control System (VCS)
Definition: A system that manages changes to files over time, allowing users to track
modifications and revert to previous versions.
Addresses two major problems:
1. Sharing of code: Enables multiple developers to share and collaborate on code
2. Versioning: Maintains history of changes and allows reverting to previous versions
Centralized vs Distributed Version Control Systems
Centralized Version Control Systems (e.g., SVN, CVS):
All developers communicate through a single central server
If central server goes down, developers cannot share code
Single point of failure
Examples: SVN (Subversion), CVS
Distributed Version Control Systems (e.g., Git):
Multiple copies of the repository can exist
Developers can work independently
No single point of failure
Each developer can have their own copy of the entire repository
Examples: Git
Git vs GitHub
Git:
Open-source distributed version control system
Command-line tool you install locally
Tracks changes in files
Can be self-hosted on your own server
GitHub (also GitLab, BitBucket):
Services built on top of Git
Provide additional features:
User-friendly interfaces
Issue tracking
Code review tools
Project management features
Pull requests
Collaboration tools
Git Core Concepts
Repository: A collection of files tracked by Git
Fork: A copy of a repository that allows you to freely experiment without affecting the original
project
Branch: A separate line of development
Commit: A snapshot of changes at a specific point in time
Main/Master: The default branch name
Basic Git Commands
1. git init : Initialize a new Git repository
2. git status : Check the status of your files (tracked, modified, etc.)
3. git add [file] : Start tracking a file or stage changes for commit
4. git commit -m "message" : Create a snapshot of changes with a descriptive message
5. git log : View history of commits
6. git diff : See changes between commits, commit and working tree, etc.
7. git reset --hard [commit] : Reset to a specific commit (discards all changes after that
commit)
8. git push : Send commits to a remote repository (like GitHub)
Git Workflow Example
1. Create a folder for your project
2. Initialize Git repository using git init
3. Create/modify files
4. Check status with git status (shows untracked files)
5. Track files with git add [filename]
6. Commit changes with git commit -m "message"
7. Make more changes to files
8. View differences with git diff
9. Stage and commit changes again
10. View history with git log
11. Revert to previous versions if needed with git reset --hard [commit-id]
GitHub Usage
Create a GitHub account
Create a new repository
Options when creating:
Public vs Private repositories
Initialize with README
Add .gitignore or license
Connect local repository to GitHub
Push code to GitHub for sharing
Fork repositories to create your own copy
Collaborate with other developers
Hidden .git Directory
Created when initializing a Git repository
Contains:
Objects folder: Stores all file versions
Refs: Contains references to commits
Hooks: Custom scripts for Git events
Config: Repository configuration
HEAD: Reference to the current commit
Advanced Concepts Mentioned
Git hooks: Scripts that run automatically when certain events occur
CI/CD with GitHub: Automated testing and deployment
Project management features
Organization management
Security features
Benefits of Git and GitHub
Better collaboration between developers
Complete history of changes
Ability to revert to previous versions
Code backup
Distributed nature prevents single points of failure
Open source community and collaboration