Post

Git & GitHub Workflows

A clear and structured revision guide covering Git and GitHub fundamentals, key concepts, workflows, and collaboration practices.

Git & GitHub Workflows

🧠 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

TermDefinition
GitA 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.
GitHubA cloud-based platform for version control using Git, enabling code collaboration and repository hosting.
Open SourceSoftware whose source code is publicly accessible under a license permitting use, modification, and distribution.
CI/CDA 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 RepositoryA version of the repository stored on your computer for personal use and updates.
Remote RepositoryAn internet-based repository for sharing and collaboration.
CommitSaving your changes as snapshots to track progress and version history.
PushUploading your local commits to a remote repository to share with collaborators.
PullDownloading the latest updates from a remote repository to your local system.
CloneCreating 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.
SnapshotA 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

FeaturePurpose
Pull Requests (PRs)Propose changes and request that they be merged into another branch (usually main).
PR ReviewsTeam members can review, comment, and suggest modifications before approval.
ForkingCreate your own copy of another user’s repository to experiment safely.
MergingOnce 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:

  1. Open the conflicting file(s).

  2. Look for markers:

    1
    2
    3
    4
    5
    
    <<<<<<< HEAD
    your version
    =======
    collaborator’s version
    >>>>>>> branch-name
    
  3. Edit to keep the correct version(s).

  4. 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

  1. Initialize your repo:

    1
    
    git init
    
  2. Configure your details:

    1
    2
    
    git config --global user.name "Alice"
    git config --global user.email "alice@example.com"
    
  3. Add files and commit:

    1
    2
    
    git add .
    git commit -m "Initial commit"
    
  4. Create and switch to a new branch:

    1
    
    git checkout -b feature
    
  5. Make edits, then merge back:

    1
    2
    
    git checkout main
    git merge feature
    
  6. Add remote and push:

    1
    2
    
    git remote add origin https://github.com/alice/my-repo.git
    git push -u origin main
    
  7. Pull 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 status and git log --oneline frequently to keep track of your current state and progress.


📚 References (Git → GitHub Workflow)

  1. Learn Git | Official — Understand version control, repositories, commits, and branches.

  2. Explore Git Commands | Official — Review official command references.

  3. GitHub Docs | Official — Learn GitHub workflows.

  4. Hello World Tutorial | GitHub Docs — Practice repository creation, commits, and pull requests.

  5. Git Tutorial | W3Schools — Beginner-friendly interactive guide.

  6. Git Cheat Sheet | Official — Quick reference of essential Git commands.

  7. Git Desktop documentation | Official — GitHub Desktop official documentation.

  8. Git Desktop on Linux | Unofficial — Installing GitHub Desktop on Linux (Unofficial, as of publishing date).

  9. Learn Git Branching | Comprehensive — Mastering Git commands, Visually.

  10. Learn Git and GitHub | Roadmap | Comprehensive - Roadmap to master Git and GitHub


This post is licensed under CC BY 4.0 by the author.