Making your First Git Commit to GitHub
Before making our first git commit let us look at Git itself.
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:
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)
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.
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.
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 ?
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.
Step 7:- Now commit the files using git commit -m “message for you to reference”. I have done the following.
Check for the git status again. This is what you will get.
You can also check the history of changes to the repository using git log command.
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.
Click on the plus sign and you will see the option to create a new repository.
Then click on New. You will be redirected to the following view.
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.
Copy this highlighted section and paste in on to the terminal like this.
Step 11:- Next enter git push -u origin master on the terminal.
The result would look like this:-
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.
You can generate your token from there.
After that head over to the terminal window and do the following:-
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.







