Sitemap

Making your First Git Commit to GitHub

6 min readMay 31, 2023

--

Before making our first git commit let us look at Git itself.

Press enter or click to view image in full size
Git logo from https://git-scm.com

Brief Introduction of Git

Let’s assume that you are a developer working remotely in a XYZ Company. The company teams you up with fellow developers who are also working remotely on a project. Now, how are you going to keep track of other’s progress or the changes they have made on the file that you created. This dilemma persistently aches your fellow developers as well. Well that is where git comes in.

Git is a very popular version control utility. It facilitates collaborative changes by providing the details on what I call the 5Ws. That is, who did what, where, why and when. And this is made possible by maintaining the history of content changes made over time by an individual member or members of a team working in tandem on a project.

GitHub is one such hosting service that uses Git for software development and version control.

Now lets take these concepts forward and see to it how we can actually implement them.

You Very First Git Commit

A GitHub account is a prerequisite to initiate this process. So, create one for yourself here. Also, I haven’t yet told you to download Git. So, download it from here.

Now kindly go through the following steps.

Step 1:- To ensure that git successfully installed on your system, head to the command line or terminal and do the following:

Press enter or click to view image in full size
Checking the Git installation

If this doesn’t show up, you don’t have your git properly installed. Make sure your installation completes. Then come back here to check the Git installation.

Step 2:- Create a directory/folder that will include that files and folders you want to commit to a GitHub repository. (repository is a GitHub jargon for a directory)

Press enter or click to view image in full size
Creating a directory with files in it.

You can follow GUI approach to perform the above-mentioned task. I have used the command line approach here through Linux bash shell. If you want to try out these commands, you can read my article on the basic Linux commands.

Step 3:- Initialize Git in your directory that houses all the files and folders you intend to push to your GitHub repository. Enter git init in the terminal window as illustrated below.

Press enter or click to view image in full size
Initializing Git in the directory

Step 4:- Next, configure your GitHub username and email through git config — global user.name “<Your user name>” and git config — global user.email “<Your email address>”

Step 5:- Check the Git status using git status command.

Press enter or click to view image in full size
Checking the Git status

Step 6:- Since we have not yet added the files to there are no commits to be made. So, lets add these files first.

You can add individual files at a time or add everything at a go. When we work with a lot a files, it is completely inefficient to add one file at a time so here we will add all the files at a go using git add . command.

Get Rupak Bhandari’s stories in your inbox

Join Medium for free to get updates from this writer.

Check the Git status again. Do you spot any changes ?

Press enter or click to view image in full size
Git status after adding the files

The files are now added to the staging area which readies the files to be committed onto a repository. You can understand this concept by looking at the next illustration.

Press enter or click to view image in full size
Photo by Jonathan Irvin from https://dev.to

Step 7:- Now commit the files using git commit -m “message for you to reference”. I have done the following.

Press enter or click to view image in full size
Committing the file to-be-transferred onto the repository

Check for the git status again. This is what you will get.

Press enter or click to view image in full size
Checking Git status

You can also check the history of changes to the repository using git log command.

Press enter or click to view image in full size
Exploring a repository history

Step 8:- Now head over to your GitHub account and create a repository. You can launch the new repository using several available options. I will use clickable + icon at the top right corner of the navigation pane to create one for this demonstration.

Press enter or click to view image in full size
You can see a plus like icon with a drop-drop on the top right corner of the screen

Click on the plus sign and you will see the option to create a new repository.

Options available upon expanding the + icon

Then click on New. You will be redirected to the following view.

Press enter or click to view image in full size
View to create a new repository

Here, insert the name of the repository you want to create. You can add description to the repository for comprehension when you visit this repository later on but it is optional and you can leave it as it is.

Step 9:- Leave the rest of the options as it is and create a repository.

Step 10:- Next, you will land to your repository page. Scroll down a bit and you should see something like this.

Press enter or click to view image in full size

Copy this highlighted section and paste in on to the terminal like this.

Press enter or click to view image in full size

Step 11:- Next enter git push -u origin master on the terminal.

Press enter or click to view image in full size

The result would look like this:-

Press enter or click to view image in full size
Result of pushing files to GitHub repository

For Linux user, this might not suffice so in such a situation a token needs to be generated. This token needs to be configured as your GitHub password rather than your default password.

You can do this by navigating to Settings > Developer Settings > Personal Access Tokens.

Settings at the end of drop-down
Developer Settings on the left-side of the page view
Press enter or click to view image in full size
Developer settings page view

You can generate your token from there.

After that head over to the terminal window and do the following:-

Press enter or click to view image in full size
Reconfigure your password using the token generated

Then, repeat the step 10 and 11. You are all good now.

Head back to the browser window and refresh the page view of your recently created repository. And yes you did it.

Thanks for reading.

--

--

Rupak Bhandari
Rupak Bhandari

Written by Rupak Bhandari

AWS Cloud Practitioner venturing in the exploration of the domain of Information Security, Python and Linux System Administration