π Git & GitHub Basics
A clear and structured revision guide covering Git and GitHub fundamentals, key concepts, workflows, and collaboration practices.
π§ Git & GitHub Basics
π Understanding Git & GitHub
πΉ What is Git?
Git is a Version Control System (VCS) that allows you to manage changes to your code and collaborate with others on projects efficiently.
β³οΈ Key Features
- Version Control: Enables users to track the history of changes and revert to previous versions if necessary.
- Distributed System: Unlike centralized systems, Git gives each collaborator a local copy of the entire project history β enhancing data reliability and flexibility.
π§© Git Terminologies
| Term | Definition |
|---|---|
| Git | A distributed version control system (VCS) that records changes to files and enables multiple developers to collaborate on a project by maintaining complete version histories locally and remotely. |
| GitHub | A cloud-based platform for version control using Git, enabling code collaboration and repository hosting. |
| Open Source | Software whose source code is publicly accessible under a license permitting use, modification, and distribution. |
| CI/CD | A development practice combining Continuous Integration (automated code testing and merging) and Continuous Deployment (automated code delivery to production). |
| VCS (Version Control System) | A system that manages and records changes to files over time, allowing restoration, comparison, and collaborative editing. |
| Β | Β |
| Repository (Repo) | A storage area for project files, acting like a project folder. |
| Local Repository | A version of the repository stored on your computer for personal use and updates. |
| Remote Repository | An internet-based repository for sharing and collaboration. |
| Commit | Saving your changes as snapshots to track progress and version history. |
| Push | Uploading your local commits to a remote repository to share with collaborators. |
| Pull | Downloading the latest updates from a remote repository to your local system. |
| Clone | Creating a local copy of a repository from a remote source. |
| Pull Request (PR) | A formal request to merge code changes from one branch into another within a version-controlled repository. |
| Snapshot | A complete record of the projectβs state at a specific point in time, created when a commit is made in Git. |
π Understanding GitHub
GitHub is a web-based platform that leverages Git for version control.
It allows hosting repositories online for collaboration, contribution, and backup.
It serves as a social platform for developers, encouraging open-source development and community contributions, where users can fork, clone, and collaborate on projects with ease.
βοΈ Workflows in Git and GitHub
1. ποΈ Creating a Repository
- You can create a repository locally using:
1
git init
- Or on GitHub, by clicking βNew Repositoryβ, naming it, and optionally initializing it with a
README.md.
2. πΎ Committing Changes
Each time you make meaningful code updates:
1
2
git add .
git commit -m "Add initial project files"
π‘ Commits act as snapshots of your project, recording progress over time.
3. πΏ Branching and Merging
Branches allow independent development of features without affecting the main code base.
1
2
3
4
5
6
git branch feature-login
git checkout feature-login
# make changes
git commit -m "Add login feature"
git checkout main
git merge feature-login
Merging integrates the changes back into the main project.
π€ Collaboration Features
| Feature | Purpose |
|---|---|
| Pull Requests (PRs) | Propose changes and request that they be merged into another branch (usually main). |
| PR Reviews | Team members can review, comment, and suggest modifications before approval. |
| Merging | Once approved, changes are merged into the main branch, integrating new features or fixes. |
β οΈ Managing Conflicts
When multiple collaborators modify the same section of a file, merge conflicts can occur.
To resolve:
- Open the conflicting file(s).
Look for markers:
1 2 3 4 5
<<<<<<< HEAD your version ======= collaboratorβs version >>>>>>> branch-name
- Manually edit the file to retain the correct lines.
Stage and commit the resolution:
1 2
git add <filename> git commit -m "Resolve merge conflict"
π§ͺ Practical Example
During hands-on sessions, you can:
- Create a new repository (
git initor via GitHub). - Add and commit changes.
Push them to GitHub:
1
git push origin main
- Create feature branches and practice merging to reinforce Git fundamentals.
π§Ύ Summary
This guide provides a clear and structured understanding of Git and GitHub essentials.
- Git handles version control and local project tracking.
- GitHub enables collaboration, hosting, and open-source contribution.
- Learn to use essential commands:
git init β git add β git commit β git push β git pull β git merge.
By following these workflows and examples, learners can manage codebases efficiently and collaborate with peers seamlessly β an essential skill set for software developers, data scientists, and ML engineers alike.
π‘ Pro Tip:
Use
git statusoften β it helps verify whatβs staged, unstaged, or untracked before committing changes.
π§ Follow this sequence β Git first, GitHub next β to build practical understanding step-by-step.
π References (Git β GitHub Workflow)
Learn Git | Official β Understand version control, repositories, commits, and branches.
Explore Git Commands | Official β Review official command references.
GitHub Docs | Official β Learn GitHub workflows.
Hello World Tutorial | GitHub Docs β Practice repository creation, commits, and pull requests.
Git Tutorial | W3Schools β Beginner-friendly interactive guide.
Git Cheat Sheet | Official β Quick reference of essential Git commands.
Git Desktop documentation | Official β GitHub Desktop official documentation.
Git Desktop on Linux | Unofficial β Installing GitHub Desktop on Linux (Unofficial, as of publishing date).
Learn Git Branching | Comprehensive β Mastering Git commands, Visually.
Learn Git and GitHub | Roadmap | Comprehensive - Roadmap to master Git and GitHub
