Exploring Git and GitHub - Part I


Hi everyone👋,
This week, we're diving into the fantastic world of Git and GitHub - two must know concepts for anyone dreaming of a software development career! In this blog series on GitHub, I'll walk you through everything from installation to key topics like branching, merging, resolving conflicts, and rebasing from scratch. Plus, I'll guide you in making your first pull request! Get ready for an exciting journey with interactive visuals and animations that reveal how these version control systems work their magic behind the scenes.
This blog does not require any prior knowledge or experience with Git! Whether you're a beginner, an open-source enthusiast, or just entering the DevOps arena, Git is an essential skill to have. This is Part I of the blog series where we cover the fundamentals of git and GitHub.
So, let's jump in and get started!
The What and Why behind a Version Control System?
Okay, let’s imagine a real-world scenario. You’ve started working on a calculator project using Python on your local machine. Now, you want to team up with your friend to develop it further.
How do you share the project? Let’s say you upload it to Google Drive, and your friend downloads it. Everything seems fine until the problems start.
You update some backend API. Your friend tweaks the frontend. Later, they send you a zip file with their changes. You replace your files, and suddenly the app breaks. Some of your changes are gone, and you have no idea what went wrong.
Now, you need to undo everything, but you can’t.
Now, you wish for a time machine to return to when everything was fine.
Well, Git is that time machine for you! It keeps track of all your changes, so you can easily roll back, collaborate without overwriting each other’s work, and never lose progress again.
That’s what a version control system does. In simple terms, it keeps versioning your project with every sort of change you make and stores it as a history, and you can rollback or stay at your latest version whenever needed and collaborate with your teammates with no pain point.
Installing Git
Setting up git is an easy and quick process. Just navigate to this website
https://git-scm.com/downloads and download git according to your OS. Once you have downloaded, set up the environment variable and you’re done!
Why Git?
You might wonder - Why Git when there are other version control systems like Bitbucket, Mercurial or even centralised systems like SVN?
Well, Git has become the undisputed industry standard for version control. Git stands out because it’s fast, flexible and super popular due to its open-source nature, with a vast ecosystem and massive community support, making it the go-to choice. It lets you work offline, try out changes safely, and easily team up with others. Plus, most platforms(like GitHub and GitLab) are built around Git anyway, so learning Git means you’re good to go pretty much anywhere.
There are mainly two types of VCS - Version Control System:
1. Distributed VCS - Everyone has the full copy of the repo(history and all). You can work offline, commit locally, and sync when ready.
2. Centralised VCS - There’s one central server, and everyone pulls/pushes changes directly to it. You need to be online to commit.
Let’s start working!
Okie, now let’s see how to work with git step by step. Consider you are working on a calculator project with a minimalistic frontend and a backend. You create a folder and navigate to it, and you have started working.
mkdir calculator-project
cd calculator-project
code .
Let’s say you add a basic additional functionality of adding two numbers using Python.
# Get input from the user
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
# Add the numbers
sum = num1 + num2
# Display the result
print("The sum is:", sum)
Now you have your friend joining you for further developing and collaborating with the project and so you have to share this folder and both can work independently without overwriting the changes.That’s where git comes in!
To integrate git with your project, navigate to the project folder and type
git init
git init means that you’re saying git “Hey git, I have started working on this project, and you just keep track of any changes to restore its history, ok?” Now any changes you make in every file are recorded, it captures like a camera, and you can rollback whenever needed! Isn’t it cool, tho? To verify this, type
ls -a
This lists down all the hidden files that start with a dot(.)Why hidden? For security purposes, like you see an .env file in the backend for storing passwords and usernames. You will see a new .git/ folder inside the project folder. Navigate to it and let’ see what’s inside it!
Okie, that’s so huge, let me break it for you!
config | Stores repository(folder) specific configuration like username, remote URLs, and bash shell. |
description | Used in bare repositories; mostly ignored in normal ones |
HEAD | A pointer where the current branch lies. In this case, it is the master. |
hooks/ | Contains sample scripts to trigger actions at certain git events(eg, pre-commit) |
info/ | Stores additional info like exclude file patterns(like .gitignore) |
objects/ | contains all the content(commits,trees,blobs) in Git’s internal storage |
refs/ | Holds references to all branches and tags in the repository. |
To view the status of your project folder,type
Git status - allows you to view the current status of the folder. Okay, you have added an add.py file and but it is not tracked yet. You need to authorise it to add it to a ready queue. To add it, simply type
As you can see, now the add.py file is moved to the tracked stage(staged).
NOTE: Ignore the warning message for now, as it does not affect anything!
Now comes the important part: you need to commit your changes
git commit - “Alright Git, save this change with a message given using the -m option inside quotations!”. As you can see, one file, i.e add.py, is changed with 9 lines of code(inserted) and no deletion is there. When you commit, you should send a message, and it is not an optional thing.
Okay, being bored as a single? You can at least commit with git tho😅😜
Jokes apart! Once you have committed the changes, what’s next? You have to push the changes. Cool, but the real question is, push where? Let’s explore that next!
Github-Quick Intro
Github is like home for your git tracked projects - it’s where you store, share, and collaborate on code with others. It provides you nice user web interface and allows you to contribute to opensource projects easily. It gives your Git projects a central place to live and lets the world see or contribute to them.
Key Features
Repositories - Your project folders with code and other stuff in simple terms.
Commits & Branches - Just like Git, but you can track them visually on GitHub. It shows your commit history, commits, branches, and changes.
Pull requests (PRs) - Want to suggest changes? PRs let you propose edits, and others can review and merge them.
Issues - Like a to-do list or bug tracker for repositories (repos in short).
GitHub Actions (CI/CD) - Automate testing, builds, and deployments straight from your repo.
Stars & Watching - You can star repos like you bookmark them and watch repos to stay updated.
Projects & Discussions - For organizing tasks like kanban-style and chatting about your ideas or roadmaps.
Okay, there are so many platforms(Gitlab, Bitbucket)out there, but we use GitHub for most activities as it is easy and beginner friendly. To get started with GitHub, follow steps below
Step 1: Head over to github.com and sign up - it’s free. All you need is an email & a cool username😄.
Step 2: Once you’re done, create a repo
Click the + icon on the top right → New repository
Name it. I love to name it as git-github-demo simply
You can leave it public/private based on preference.
Skip Readme for now (we already have our project now)
No license required for now as well (we'll look more into that later)
Step 3: Now, copy the Remote URL which we need, present under the code tab. For now, hang on with the HTTPS URL itself
Step 4: Now navigate to VS Code and inside the project folder, type
git remote add - with the name of the URL. I want to name it as origin, as it is the default conventional name for any remote repository, followed by the URL that you have copied before. To verify whether the folder is attached to a remote URL, cross check it by git remote -v and it should show the URL with two options both to push and fetch as seen below.
Before pushing the changes, we’ll look into the branching strategy in git for sometime as it’s a prerequisite.
Branching
Git stands out compared to other version control systems because of its best branching strategy. A branch is like a copy of your codebase where you can make changes safely, without disturbing the original code branch.
These are some branching strategies you should know
main/master - This is the production-ready code, meaning people are using it in real-time applications.
dev - A place where all active development happens before moving to the main branch.
feature branch - Created for each new feature or enhancement, mostly used for creating new pull requests.
How to check which branch you are working on currently? To know, simply do
git branch - allows you to view the branch that you’re currently working on.In this case,it’s a master branch and the star pointer that you’re seeing is the HEAD which is currently pointing to master branch.
- Create a new branch in the git repo, use
git branch - creating a new feature branch, followed by the branch name. Let’s add a subtraction functionality to the calculator app. This only creates a new branch without switching to the new branch, and you’re still on your master branch(HEAD) only as you can see below.
2. Create and switch to it
git checkout - It creates a new branch and switches to the newly created branch. Here, (-b) means branch, and checkout means switch to it. I’m adding Division functionality, as you can see. If you try to list out git branches, it lists 2 feature branches and the default master branch with HEAD pointing to division branch. Cool!
For simply switching btw branches, just use
To delete a branch after you’re done with a feature and it’s merged, type
git branch with the -d option, followed by a branch name that you want to delete. I successfully deleted the division branch, as I don’t want it anymore!
Remember, if it’s not merged and you still want to delete,you can forcefully delete using with uppercase D.
git branch -D my-feature
Here's a complete video to help you visualize how the branching system works in Git. Shoutout to learngitbranching.js.org for making this so much easier!
That’s all about Git branching strategy, I hope that makes sense to you right now😚
Forking and Cloning
Think of forking like this: “Hey GitHub, I love this project! Can I take a copy of it into my own account so I can play around, make changes, or contribute?”
When you fork a repo:
You’re creating your own version of someone else’s project on your GitHub account.
You can make changes without affecting the original project.
It’s often the first step before contributing to open-source.
But how to fork? It’s so simple. Just hang on! You will find a fork button on the top right of every git repository as given below.
Clone
After forking, you need the code on your local machine to work with it. That’s where cloning comes in:
“Hey Git, pull this entire repo from my Github account to my machine so I can code locally!”
You can do this via two ways: HTTPS & SSH(Secure shell).For now, just hang on with HTTPS.
To clone, just use git clone followed by the URL that you’ve copied.
That’s about forking and cloning in github.Great job so far!
Pushing changes to Github
Now let’s see how to push changes to your github repo. In the project folder, so far we have been making all additions,deletions in the master branch. But github always has main branch as their default one.So before pushing,
git checkout -b main
And then fetch any remote changes to your local folder. This can be done using
git fetch origin - It’s like “Hey git, go check what’s new on github, but don’t touch my local files yet. Just show me what’s changed!”.
It just fetches the latest updates from the remote URL(origin)
Then do,
git pull origin main —allow-unrelated-histories - This command pulls changes from the main branch on GitHub and merges them into your current local branch even if their histories don’t match. why we do this ? Let’s look into more on this later !
At last we can push changes to github,
git push origin main - “Hey git,take all my local changes on the main branch and upload them to Github under the same branch!”
It’s like saying, “I’m done coding now save it to the cloud so others or future me can see it.
This command shows that you’ve successfully uploaded your local commits on the main branch to the main branch on github!
You can see this on GitHub as well. Tada 😄, all our files are pushed successfully! Alright,Cool!
Pull requests and your first contribution!
Make your very first opensource contribution here👇. I have created a sample repository for the calculator application. Please follow these steps to make some code contribution.
1. Fork the repo : Head into https://github.com/Devisrisamidurai/git-github-demo and click on fork button and copy the main branch only.
2. Clone the repo that was recently forked on your github account using git clone via HTTP.
3. Make some changes in the code
For now the app only has addition functionality.You can add subtraction,division etc,, or just and readme file on how to use the application giving generalized overview.
4. Add the changes and commit using git commit
5. Fetch and push the changes.
Once you push, it shows raise a Pull request as given below! I have sub.py file for subtarction functionality in the subtract branch. Ensure you’re on the feature branch to make PR’s as you cannot make it in Main default branch.
Click that , it will take you the PR description page. Give a detailed description on what changes you have made and how it improves the functionality with a clear concise title.
Once you’re done with this,Click on create Pull request button below and yeah it’s done!Congrats to you🤗
That’s it for this lecture. If you have come this far, I highly appreciate it💙. It’s a huge step in your learning process🙌.
IMPORTANT!
Do like the blog if you found it useful and share it with your friends!
Conclusion
No matter how many tutorials you watch or blogs you read (even the really detailed ones!), nothing beats getting your hands dirty and actually doing it. That’s where the real learning happens. So, go ahead and make your first contribution! Grab the repo, make sure your pull request is meaningful — no spammy stuff, because only valuable PRs will get reviewed and merged for the demo project.
In this post, we’ve covered the basics: initiating the project with git,committing changes, branching, pushing, cloning, and forking. These are the foundation of working with Git and GitHub.
Next up in the series, we’ll dive into some more advanced stuff like merge, rebase, and cherry-pick and other important concepts — so stay tuned!
Thanks for reading!
Until then, Byeeee👋
Subscribe to my newsletter
Read articles from Devisri directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Devisri
Devisri
Hello,I'm Devisri, currently a sophomore working towards my undergraduate degree. I have a strong interest in technology and am dedicated to sharing my learning journey and knowledge with the community. I am currently exploring frontend web development and data science, and I'm actively honing my skills in data structures and algorithms using Java. Excited about Opensource Technologies and cloud-native communities!!