Git in Action!

2025-10-17

#git #github #open-source #hacknight7.0

Saijyoti Panda, Pranav V Bhat

Have you ever broken something in your project and wished you could go back in time? Or wanted to share your code with the world but weren't able to? That’s where Git and Github come in. They make saving changes, sharing code and collaborating easy :D

Why Git? And What Is It Anyway?

If you ever made a project, you would be familiar with something like this:

Multiple project folders showing version chaos

Git lets you manage all versions of a project inside a single repository instead of creating multiple folders.

Now, what is Git exactly?

Git is a version control tool that keeps track of all the changes you make in your project. It lets you experiment with new features safely and collaborate with others without breaking anything.

Think of it as a time machine for your code where you can go back, explore past versions and undo mistakes. Maybe even look at Linus Torvalds' past commits for Linux and fix some bugs!

Isn't it cool to have the power to jump back to any version of your project, whenever you want?

And when you power Git with Github, it opens the door to a world of endless possibilities!

You are no longer restricted to just your friends or your college. The world is your playground! It's like unlocking a whole new superpower ;)

Installing Git & Setting up SSH

If you haven't installed Git yet, don't worry! Follow the instructions below to install Git and set up your SSH keys based on your OS :)

[!NOTE] Use the username and email you use for Github, or it would lead to issues!

For Windows

Make sure you run the SSH commands inside Git Bash, not Command Prompt or PowerShell.

Generate an SSH key:

ssh-keygen -t ed25519 -C "your_email@example.com"

Start the SSH agent and add the key:

eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519

Copy your public key:

cat ~/.ssh/id_ed25519.pub

Copy the entire output as you’ll need it for GitHub.

For Linux/MacOS

Install Git (if not installed)

Ubuntu/Debian:

sudo apt update sudo apt install git

Fedora:

sudo dnf install git

Arch:

sudo pacman -S git

macOS (Homebrew):

brew install git

To install Homebrew (if you don't have it), run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Generate an SSH key

ssh-keygen -t ed25519 -C "your_email@example.com"

Start SSH agent and add key

Linux:

eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519

macOS:

eval "$(ssh-agent -s)" ssh-add --apple-use-keychain ~/.ssh/id_ed25519

Copy public key

Linux:

cat ~/.ssh/id_ed25519.pub

macOS:

pbcopy < ~/.ssh/id_ed25519.pub

Once you're done setting up SSH

Copy your public key and add it to GitHub by following the below steps:

Go to GitHub > Settings > SSH and GPG keys > New SSH key, and paste it there.

Then, run the ssh -T git@github.com command in your terminal to verify the setup.

You should see Hi <your-username>! You've successfully authenticated, but GitHub does not provide shell access.

Make sure to run the below as well:

git config --global user.name "your username" git config --global user.email "your_email@example.com"

[!NOTE] If all these methods fail, do look at something called GITHUB DESKTOP. It's just a Google Search away ^^

Creating a Repository

Creating a repo in Github is easy.

Go to your Profile, and click on the NEW button

Image of new button

Then, type in the name of the repository and click on Create Repository

Create Repository

TADA! Now you have your very own repo!

Btw, you can change the visibility later on too. Just go to Settings.

Forking and Cloning Repositories

Let's say you want to contribute to someone's repository or maybe, even an open source project! But what's the best way to do that?

Well, that’s where Forking comes in. 'Forking' a repository means creating your own copy of the repository so you can experiment and make changes safely without affecting the original project.

And how is that done?

How to fork a repository

Click on Fork

Image of fork option

Then, click on Create Fork

Now that you have your own copy of the repository, you might be wondering how to work with it on your local system. This is where Cloning comes in!

Cloning the Repository

This lets you copy the repository to your local system so you can work on it locally.

Run git clone <insert-the-repo-link>

and where do you find this URL?

Image of Clone links

[!NOTE] Click on SSH and copy link if you have the SSH Setup!

Working with Branches

Hmm.... what if I want to experiment with a feature? Is there any way to do that without having to create multiple folders?

YES! Branches let you work on separate versions of your project without affecting the main code. Once you are satisfied, you can merge them to the main branch.

Interesting, isn't it? But how do you make a new branch?

Run the following commands in your terminal:

# Check which branch you are on git branch # Create a new branch and switch to it git checkout -b your-new-branch-name # Switch to an existing branch git checkout name-of-the-branch

Git Commits

Remember we talked about exploring past versions? But how are these versions made?

Commits let you do all these cool stuff. They let you take a snapshot of your project at a point in time.

Before committing, make sure you’ve added all the files you want to track:

# Add specific files git add file1 file2 # Or add all changes git add .

Then, commit your changes with a message:

git commit -m "Describe your changes"

We recommend using Commit Conventions to keep your messages clear.

[!Tip] Pull latest changes before you start work and before you push, to avoid conflicts and keep your branch up to date.

# Pull latest changes for your current branch git pull # If you're on a feature branch git pull origin your-branch-name

It's important to note that these latest commits stay on your local system until you Push them to Github:

# Push changes to the main branch git push origin main # Push changes to a different branch git push origin your-branch-name

An example:

Commit Image

Pull Requests

Once you’ve made changes on your branch and committed them, it’s time to share your work with the original project. That’s what a Pull Request (PR) does.

A PR is basically saying:

“Hey, I made some changes! Can you review them and merge them into the main project?”

How to create a PR

Click on Compare & pull request

Compare and PR

Then, write a description of the changes you made (look out for templates if any), double-check the branches at the top, and click Create Pull Request.

Image of Pull Request

More places to learn from!

A very interesting video to look out for if you have the time:

So You Think You Know Git?

That brings us to the end of the blog.

We’ve covered most of the basics of Git and GitHub here. There’s still a lot more to explore, for example, things like merge conflicts, rebasing and deeper Git workflows.

Maybe we’ll dive into those in our next Git blog! ^^