Exploring Git and GitHub - Part I
A Time machine for your project

Hello, I'm Devisri, currently an undergraduate student working towards my 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 web dev, and I'm actively honing my skills in data structures and algorithms using Java. Excited about Opensource Technologies and cloud-native communities!!
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!
Before diving in, Connect git with your username and email for configuration purposes.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Done! 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đ




