Git and Github
Introduction to Version Control and Collaboration
This section provides an introduction to version control using Git and collaborative development with GitHub. It covers the basics of Git, including how to create repositories, commit changes, and manage branches. Additionally, it explores how to use GitHub for hosting repositories, collaborating with others, and contributing to open-source projects.
What is Git?
Git is a distributed version control system (DVCS). Unlike older systems (like Subversion or CVS) that rely on a central server, Git allows every developer to keep a full copy of the repository, including its history, on their local machine.
Key benefits:
- Version Tracking: Every change is saved as a commit, with a timestamp, author, and message.
- Branching & Merging: Developers can create branches for experiments, bug fixes, or features, then merge them back into the main project.
- Local-first: Work offline and sync changes later.
- Safety: Commits are checksummed with SHA-1 hashes, making it nearly impossible to corrupt or lose history without detection.
Example workflow in Git (local):
git init # Initialize a new Git repository
git add . # Stage all changes for commit
git commit -m "Initial commit" # Commit changes with a message
git branch feature-login # Create a new branch
git checkout feature-login # Switch to branch
What is GitHub?
GitHub is a cloud-based hosting platform for Git repositories. It adds collaboration, social, and automation layers on top of Git:
- Hosting – Push your local repo to GitHub to share with others.
- Collaboration – Teams can work on the same code using forks, pull requests, and code reviews.
- Issue Tracking – Report bugs, request features, or assign tasks.
- Actions (CI/CD) – Automate testing and deployment when new code is pushed.
- Community & Networking – Developers showcase work and connect with peers.
Git vs. GitHub
In summary, Git and GitHub serve different but complementary purposes:
- Git = tool you install and use locally
- GitHub = web service that hosts your Git repos and makes teamwork easier