|
| 1 | +--- |
| 2 | +title: 'Git in Action!' |
| 3 | +description: 'Unlock the Power of Version Control' |
| 4 | +authors: Saijyoti Panda, Pranav V Bhat |
| 5 | +tags: ['git', github, 'open-source', 'hacknight7.0'] |
| 6 | +date: '2025-10-17' |
| 7 | +--- |
| 8 | + |
| 9 | +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 and collaborating easy :D |
| 10 | + |
| 11 | +## Why Git? And What Is It Anyway? |
| 12 | + |
| 13 | +If you ever made a project, you would be familiar with something like this: |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +Git lets you unify all this into a **_SINGLE_** folder! |
| 18 | + |
| 19 | +_Now, what is Git exactly?_ |
| 20 | + |
| 21 | +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. |
| 22 | + |
| 23 | +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 Toravlds' past commits for Linux and fix some bugs!_ |
| 24 | + |
| 25 | +_Isn't it cool to have the power to jump back to any version of your project, whenever you want?_ |
| 26 | + |
| 27 | +And when you power Git with Github, it opens the door to a world of endless possibilities! |
| 28 | + |
| 29 | +- You can share your projects online so anyone can see or use them. |
| 30 | +- You can collaborate globally on projects with friends or contributors. |
| 31 | +- You can contribute to open-source projects and learn from code written by others. |
| 32 | + |
| 33 | +_You are no longer restricted to your just friends or your college. The world is your playground! It's like unlocking a whole new superpower_ ;) |
| 34 | + |
| 35 | +## Installing Git & Setting up SSH |
| 36 | + |
| 37 | +If you haven't installed Git yet, don't worry! We have some scripts for you that you could run to download Git and also set an SSH key for the same! |
| 38 | + |
| 39 | +> [!NOTE] |
| 40 | +> Use the username and email you use for Github, or it would lead to errors! |
| 41 | +
|
| 42 | +### For Windows |
| 43 | + |
| 44 | +Run this in as Admin in Powershell: |
| 45 | + |
| 46 | +```bash |
| 47 | +Invoke-RestMethod -Uri "https://gist.githubusercontent.com/Prana-vvb/b2602c1aafb692691a88d167a1d9f645/raw/523f2fd69f58a0ecf0c43a251d0320d5fc21775b/setup_windows.ps1" | Out-File -FilePath "setup.ps1"; .\setup.ps1 |
| 48 | +``` |
| 49 | + |
| 50 | +### For Linux/MacOS |
| 51 | + |
| 52 | +Run the below command: |
| 53 | + |
| 54 | +```bash |
| 55 | +bash <(curl -sS https://gist.githubusercontent.com/Prana-vvb/5f48ae8e1173f7b1db105d80c70c2542/raw/10241f14b24427834cebd24128a4fa801fdac148/setup_unix.sh) |
| 56 | +``` |
| 57 | + |
| 58 | +Copy your public key and add it to GitHub by following the below steps: |
| 59 | + |
| 60 | +Go to GitHub > Settings > SSH and GPG keys > New SSH key, and paste it there. |
| 61 | + |
| 62 | +Then, run the `ssh -T [email protected]` command in your terminal to verify the setup. |
| 63 | + |
| 64 | +You should see `Hi <your-username>! You've successfully authenticated, but GitHub does not provide shell access.` |
| 65 | + |
| 66 | +> [!NOTE] |
| 67 | +> If all these methods fail, do look at something called GITHUB DESKTOP. It's just a Google Search away ^^ |
| 68 | +
|
| 69 | +## Creating a Repository |
| 70 | + |
| 71 | +Creating a repo in Github is easy. |
| 72 | + |
| 73 | +Go to your Profile, and click on the `NEW` button |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +Then, type in the name of the repository and click on `Create Repository` |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +**_TADA! Now you have your very own repo!_** |
| 82 | + |
| 83 | +Btw, you can change the visibility later on too. Just go to Settings. |
| 84 | + |
| 85 | +## Forking and Cloning Repositories |
| 86 | + |
| 87 | +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?_ |
| 88 | + |
| 89 | +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. |
| 90 | + |
| 91 | +And how is that done? |
| 92 | + |
| 93 | +### How to fork a repository |
| 94 | + |
| 95 | +Click on `Fork` |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +Then, click on `Create Fork` |
| 100 | + |
| 101 | +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! |
| 102 | + |
| 103 | +### Cloning the Repository |
| 104 | + |
| 105 | +This lets you _copy the repository_ to your _local system_ so you can work on it locally. |
| 106 | + |
| 107 | +Run `git clone <insert-the-repo-link>` |
| 108 | + |
| 109 | +_and where do you find this URL?_ |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | +> [!NOTE] |
| 114 | +> Click on SSH and copy link if you have the SSH Setup! |
| 115 | +
|
| 116 | +## Working with Branches |
| 117 | + |
| 118 | +Hmm.... what if I want to experiment with a feature? Is there any way to do that **_without having to create multiple folders_**? |
| 119 | + |
| 120 | +YES! **_Branches_** let you create multiple parallel versions that you can safely work. Once you are satisfied, you can **_merge_** them to the `main` branch. |
| 121 | + |
| 122 | +_Interesting, isn't it? But how do you make a new branch?_ |
| 123 | + |
| 124 | +Run the following commands in your terminal: |
| 125 | + |
| 126 | +```bash |
| 127 | +# Check which branch you are on |
| 128 | +git branch |
| 129 | + |
| 130 | +# Create a new branch and switch to it |
| 131 | +git checkout -b your-new-branch-name |
| 132 | + |
| 133 | +# Switch to an existing branch |
| 134 | +git checkout name-of-the-branch |
| 135 | +``` |
| 136 | + |
| 137 | +## Git Commits |
| 138 | + |
| 139 | +Remember we talked about exploring past versions? But how are these versions made? |
| 140 | + |
| 141 | +**_Commits_** let you do all these cool stuff. They let you take a _snapshot_ of your project at a point in time. |
| 142 | + |
| 143 | +Before committing, make sure you’ve added all the files you want to track: |
| 144 | + |
| 145 | +```bash |
| 146 | +# Add specific files |
| 147 | +git add file1 file2 |
| 148 | + |
| 149 | +# Or add all changes |
| 150 | +git add . |
| 151 | +``` |
| 152 | + |
| 153 | +Then, commit your changes with a message: |
| 154 | + |
| 155 | +```bash |
| 156 | +git commit -m "Describe your changes" |
| 157 | +``` |
| 158 | + |
| 159 | +We recommend using [Commit Conventions](https://www.conventionalcommits.org/) to keep your messages clear. |
| 160 | + |
| 161 | +> [!Tip] |
| 162 | +> Pull latest changes before you start work and before you push, to avoid conflicts and keep your branch up to date. |
| 163 | +
|
| 164 | +```bash |
| 165 | +# If you're working directly on main |
| 166 | +git pull origin main |
| 167 | + |
| 168 | +# If you're on a feature branch |
| 169 | +git pull origin your-branch-name |
| 170 | +``` |
| 171 | + |
| 172 | +It's important to note that these _latest commits stay on your local system_ until you **_Push_** them: |
| 173 | + |
| 174 | +```bash |
| 175 | +# Push changes to the main branch |
| 176 | +git push origin main |
| 177 | + |
| 178 | +# Push changes to a different branch |
| 179 | +git push origin your-branch-name |
| 180 | +``` |
| 181 | + |
| 182 | +An example: |
| 183 | + |
| 184 | + |
| 185 | + |
| 186 | +## Pull Requests |
| 187 | + |
| 188 | +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. |
| 189 | + |
| 190 | +A PR is basically saying: |
| 191 | + |
| 192 | +> “Hey, I made some changes! Can you review them and merge them into the main project?” |
| 193 | +
|
| 194 | +### How to create a PR |
| 195 | + |
| 196 | +Click on `Compare & pull request` |
| 197 | + |
| 198 | + |
| 199 | + |
| 200 | +Then, write a description of the changes you made, double-check the branches at the top, and click `Create Pull Request`. |
| 201 | + |
| 202 | + |
| 203 | + |
| 204 | +### More places to learn from! |
| 205 | + |
| 206 | +- [Git Cheatsheet](https://git-scm.com/cheat-sheet) |
| 207 | +- [Official Git documentation](https://git-scm.com/doc) |
| 208 | +- [Git up and running - Anirudh Rowjee](https://rowjee.com/blog/git_up_and_running) |
| 209 | + |
| 210 | +That brings us to the end of the blog. |
| 211 | + |
| 212 | +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. |
| 213 | + |
| 214 | +Maybe we’ll dive into those in our next Git blog! ^^ |
0 commit comments