Learn Git and GitHub


Imagine writing 1000 lines of code… and breaking everything with one accidental change.
Now imagine a magical time machine that lets you go back, recover lost code, or even try crazy experiments without consequences.
That’s version control — your code’s safety net, your productivity booster, and your best friend as a developer.
In this blog, you’ll learn:
What Version Control Systems are
How Git and GitHub fit in
Must-know Git CLI commands
Real-world workflows
A Version Control System (VCS) is a software tool that helps manage and track changes to files, especially source code, over time. It allows multiple people to work on a project simultaneously, keeps a complete history of every change made, and enables developers to revert files or entire projects back to previous states if needed.
Key Features:
Tracking Changes
Collaboration
Branching and Merging
Backup and Restore
There are 2 types of VCS:
Centralized VCS: There is a central repository containing the codebase and developers commit their changes directly. Example: SVN
Distributed VCS: Every developer has a full copy. Example: Git
Git is a Distributed Version Control System (DVCS) that helps developers track changes in their source code, collaborate with others, and manage code history efficiently.
Key Charecteristics of Git:
Distributed Architecture
Snapshots of entire file system each time you commit
Fast and efficient
Branching and Merging
Data Integrity
GitHub is a web-based platform that provides hosting for Git repositories, making it easier for individuals and teams to collaborate on software development projects. It builds on Git’s version control functionality by adding features for collaboration, project management, and code sharing—all accessible through a web interface.
Git vs. GitHub:
Git is the tool that tracks changes in your code.
GitHub is the platform that hosts your code and supports collaboration around it.
Git CLI Commands:
Setup and init
git config -- global user.name "Your name"
Set your name
git config -- global user.email "Your email"
Set your email
git init
start a git repo in your project folder
git clone "your repo url"
download a remote repo locally
staging and commiting
git status
show what’s all changed
git add .
stage all changes
git add <your file>
stage a specific file
git commit -m “message”
save a snapshot of saved changes
branching and committing
git branch
list all branches
git branch <name>
create branch
git checkout <name>
switch to branch “name”
git checkout -b <name>
create and switch to branch “name”
git merge <name>
merge branch “name” into current one
Inspecting and comparing
git log
view commit history
git diff
see unstaged changes
git diff <b1> <b2>
compare branches
git show <commit id>
show what changed in a commit
Remote sharing
git remote -v
see all linked remote repos
git push origin <branch>
upload your branch to github
git pull origin <branch>
download changes from github
git fetch
get updates without merging
undoing and rewriting
git reset
Undo commits
git revert <commit id>
creates a new commit that reverts the previous commit
git restore <file>
Undo file changes
git stash
Temporarily save uncommitted changes
git stash pop
bring back stashed changes
git rebase <branch>
apply commits of current branch ahead of new branch
Top Picks of Git:
Branching:
A branch is basically a pointer to a specific commit in the Git history. The default branch in most repositories is called main
(or sometimes master
). When you create a new branch, Git creates a new pointer that you can move independently of main
.
To develop features in isolation
To fix bugs separately
To experiment without risk
To collaborate without interfering with others' work
Merging:
Merging in Git is the process of combining changes from one branch into another. It’s how you bring your work (like a feature or a fix) back into the main codebase after working on it separately.
Merge Conflicts in git arises when git tries to merge to branches and if same file is being modified in both the branches then git is not sure which version to be picked so then merge conflict arises. Quick hack for it is manually adjust the changes and git add <file>
and git commit -m <resolved merge conflict>
Pull Requests:
A Pull Request is a request to "pull" your changes from one branch (usually in your fork or a feature branch) into another branch (often the main
branch of the original repo).
When you finish working on a feature or bug fix.
When you want your changes reviewed before adding them to the main project.
When you're contributing to someone else's repository (e.g., open source).
Force pushing:
A force push (git push --force
) is a Git command that overwrites the remote branch with your local branch, regardless of what's on the remote.
It’s powerful — and a bit dangerous — because it can rewrite history, removing commits on the remote that others might be relying on.
In Git, HEAD
is a pointer that usually points to the latest commit of your current branch.
But when you checkout a specific commit (not a branch), HEAD
points directly to that commit, not to a branch name — that’s what we call a detached HEAD state.
Scenario Based Example:
The team is working on a Dark Mode toggle. Anya, the lead, outlines the branch strategy — all feature branches must branch off develop
, and no direct commits are allowed on main
.
Ravi begins building the frontend toggle on feature/dark-mode-ui
, while Priya sets up the backend API to save user preferences in feature/dark-mode-api
.
Midway, a bug fix is merged into develop
, so Priya uses git rebase
to update her branch — she resolves a small merge conflict in ThemeContext.js
using VS Code.
Ravi finishes first and merges his branch into feature/dark-mode
, followed by Priya after testing. Sameer runs QA, finds a bug, and Priya reverts the commit safely using git revert
.
Once everything looks good, Anya opens a Pull Request from feature/dark-mode
to develop
. After review, the team squashes commits for clean history, merges to develop
, and Zoya handles the production deployment by merging to main
and tagging the release.
You’re part of a 5-person dev team building a Dark Mode toggle for your web app TaskTrackr. You’ll go from planning → building → testing → deploying, using Git and GitHub at each step.
🧾 Full Development Lifecycle Table with Git Concepts
Stage | What's Happening | Who's Involved | Key Git Concepts / Commands |
1. Planning | Feature is discussed, branch strategy is decided (e.g. use feature/* branches) | Anya (Tech Lead) | Naming conventions, main / develop / feature/* structure |
2. Setup | Create branches for each task | Ravi, Priya | git checkout -b feature/dark-mode-ui |
3. Development | Code is written separately in branches | Ravi (UI), Priya (API) | git add , git commit , git stash , .gitignore |
4. Stay Updated | Devs sync with latest develop updates | Ravi, Priya | git pull , git fetch , git rebase develop |
5. Merging | Feature branches are merged into feature/dark-mode | Ravi, Priya | git merge , merge conflicts, git diff , git log |
6. Testing | QA tests feature/dark-mode | Sameer (QA) | None directly, but QA might check commits or log history |
7. Bug Fixes | Bugs are found and commits need to be reverted or fixed | Priya, Ravi | git revert , git reset , git checkout -- <file> |
8. Pull Request | Final PR opened to develop branch | Anya (Lead) | GitHub PR, Squash Merge, labels, reviewers |
9. Code Review | Changes reviewed and approved | Team | PR comments, changes requested |
10. Final Merge | Merged into develop → tested → merged into main | Zoya (DevOps), Anya | git merge , GitHub protected branches, GitHub Actions trigger |
11. Release | App deployed live with dark mode | Zoya | git tag v1.2 , main release branch, auto-deploy pipelines |
This is how concepts of git and github are used in the enterprises.
Subscribe to my newsletter
Read articles from Sahithya Priya directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Sahithya Priya
Sahithya Priya
Devops engineer with skills in AWS, Git, Docker, Kubernetes, Ansible, Terraform. My skills include intermediate level of knowledge in Python, Shell scripting and beginner level in YAML.