Home Let's Git and Hub it !
Post
Cancel

Let's Git and Hub it !

make your hands dirty with Github!

The Tale:

It was the summer of 2017, and my friends and I decided to make a short film for a contest in our town. We were all enthusiastic about the project, but none of us had any specific roles in filmmaking, so we all ended up doing a bit of everything.

As with any film, we started by writing the story. We all had a clear idea of the point we wanted to make through the film, so we put our heads together and penned down the first part of the story. At the end of the day, we took copies of the already-written story to develop and add our individual ideas.

The next morning, we ended up with seven different versions of the same story! To make matters worse, some of the stories were developed from different points of the story than others. We were frustrated and overwhelmed by the pile of papers in front of us.

That’s when it hit us: what if we had a version control system to track all the changes and merge them? Little did we know that a system had already been created 12 years earlier in 2005 by Linus Torvalds, one of the greatest minds in tech today! Linus is also the creator of the Linux operating system.

If only we had known about Git back then, it would have saved us so much time and effort in managing all those different versions of the story. But hey, you know it now. let’s start Git-ting!

The Path:

Technically, Git is a free and open-source, distributed version control system. It uses a file system internally to keep track of changes and versions of different files. By this it supports collaborating with people, tracking changes and rollback options on files.

Get git at Git

After installing Git, configure your Git username and email, Git uses your username and email to associate your work. Set them up using the following commands.

1
2
$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"

To ensure your Git configuration is set up correctly, you can use git config--list command to view your settings.

GitHub leverages Git’s capabilities and provides a web-based platform to host repositories in the cloud. Similar to GitHub, there are other platforms like GitLab, Bitbucket, and many others that provide similar capabilities for hosting Git repositories and many other capabilities too.

Let us start by creating a repository in gitHub or sky or cloud.

‘Repository’ here means a folder that contains all the files and their related information.

First, go to GitHub and sign up for a free account and follow the video below to create a repository.

Now, Head over to the folder where you want enable git and import the remote repository from github using git clone command

1
git clone https://github.com/talesoftechnology/github_repository.git

We can get the url of the repository from github as shown in the below screenshot

Now change the directory to the repository folder as we just cloned it from github.

1
cd github_repository

check for the readme file we created while creating github repository in directory now. To check run

1
ls

you will see the output as below listing the created read me file

Now let us modify the same file and push it up to github and verify

Open the file in your favorite editor to edit it

if you are using VS code you can open up the file by the command below

1
code README.md

add the line in the repository “ This is the line from my computer”

run git status it lists all the changes since the last clone from github repository

Stage all the changes on the current folder by running git add .

Verify the staging by running git status again, the changed file must go green

Now commit the change to the file by running

1
2
3
4
> git commit -m "added a line from my computer"

[main d4affb7] added a line from my computer
 1 file changed, 2 insertions(+)

Now the big part let us push it to the remote repository by running the command git push

1
2
3
4
5
6
7
8
9
10
> git push

Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 319 bytes | 106.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/talesoftechnology/github_repository.git
   2acc4dc..d4affb7  main -> main

Login to gitHub and verify the commit and push

I will add a video below verifying our line push to remote repository from local computer

Done!!! We cloned, added, committed, and pushed back.

This is how we leverage git to track. We can also use git locally to track different changes by commits. Every commit corresponds to a unique hash to store everything of the commit.

The Challenge:

Using previously learned concepts,

  1. Make some changes in the github repository and pull it back to our locak computer.
  2. Create a file in the local system and push it back to github repository

More on commits and branches. please stay tuned

Thank you for reading. This is part 1 of Git - it. More articles on same topic. Coming soon!

Follow us on tales of technology for more such articles.

our twitter profile - toftechnology

My Linkedin profile to follow - Herald’s linkedin

please comment below for any queries or feedback

This post is licensed under CC BY 4.0 by the author.

Nmap in the movies !

Pangea Cyber a Spaas for developers Part 1