Git & GitHub Workflows
A clear and structured revision guide covering Git and GitHub fundamentals, key concepts, workflows, and collaboration practices.
🧠 Git & GitHub Workflows
📘 Understanding Git & GitHub Workflows
🔹 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
The Git SDLC (Software Development Lifecycle) follows this intuitive sequence:
Initialize → Configure → Stage → Commit → Branch → Merge → Sync → Collaborate
1. 🏗️ Creating and Initializing a Repository
Start a new project directory and set it up for version control:
1
2
3
mkdir my-project
cd my-project
git init
Initializes a local repository in the current folder.
- Or on GitHub, by clicking “New Repository”, naming it, and optionally initializing it with a
README.md.
If you’re using Git for the first time, configure your identity:
1
2
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
View all configurations:
1
git config --list
Or clone an existing remote repository instead of creating a new one:
1
git clone https://github.com/username/repository.git
You can also create a new repository directly on GitHub and clone it locally.
2. 💾 Tracking and Committing Changes
Check file status before staging:
1
git status
Stage specific files or all changes:
1
2
git add <filename>
git add .
Commit staged files to save the current snapshot:
1
git commit -m "Add initial project files"
Amend the previous commit if needed:
1
git commit --amend
View commit history:
1
git log --oneline
💡 Commits act as snapshots — milestones of your project over time.
3. 🌿 Branching and Merging
Create a new branch to work on a feature independently:
1
2
git branch feature-login
git checkout feature-login
Or create and switch in one step:
1
git checkout -b feature-login
Make your changes, then commit them:
1
2
git add .
git commit -m "Add login feature"
Switch back to the main branch and merge your work:
1
2
git checkout main
git merge feature-login
Delete a merged branch to keep the repository clean:
1
git branch -d feature-login
List all branches:
1
git branch
4. 🔄 Synchronizing with Remote Repository
Connect your local repo to a remote GitHub repository (only once per project):
1
git remote add origin https://github.com/username/repository.git
Verify remote connection:
1
git remote -v
Push your local commits to the remote repository:
1
git push -u origin main
Fetch updates from the remote repository without merging:
1
git fetch origin
Pull updates and automatically merge them into your local branch:
1
git pull origin main
5. 🤝 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. |
| Forking | Create your own copy of another user’s repository to experiment safely. |
| Merging | Once approved, changes are merged into the main branch, integrating new features or fixes. |
6. ⚠️ 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
Edit to keep the correct version(s).
Stage and commit the fix:
1 2
git add <filename> git commit -m "Resolve merge conflict"
If needed, abort a problematic merge:
1
git merge --abort
7. 🧪 Practical Example — Full Workflow Summary
Initialize your repo:
1
git init
Configure your details:
1 2
git config --global user.name "Alice" git config --global user.email "alice@example.com"
Add files and commit:
1 2
git add . git commit -m "Initial commit"
Create and switch to a new branch:
1
git checkout -b featureMake edits, then merge back:
1 2
git checkout main git merge feature
Add remote and push:
1 2
git remote add origin https://github.com/alice/my-repo.git git push -u origin mainPull updates when others contribute:
1
git pull origin main
🧾 Summary
Git SDLC Flow (Simplified): git init → git config → git status → git add → git commit → git branch → git merge → git remote add → git push → git pull
By following these commands in order, you can smoothly manage local and remote repositories, collaborate confidently, and maintain a clean project history.
💡 Pro Tip: Run
git statusandgit log --onelinefrequently to keep track of your current state and progress.
📚 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