Introduction

In our previous article, we demonstrated how we would push our git repositories from our local system out to GitHub. In this article, we will demonstrate how we would actually make changes in a file within a repository on GitHub and then pull the changes/updates to our local machine.

 

Demonstration:

I’ll continue to use the git repository perl_scripts_for_training that we had created and pushed to GitHub in our previous article. From among the files present in that repository, we’ll select a file named say.pl. To select the file we simply need to click on its name and the file will be opened in GitHub. This will open the file in GitHub as shown in the below screenshot:

On the right-hand corner of the window where the file has been opened, we can see a couple of tabs. If we click on the Raw tab then GitHub will open the file in text format on the browser. If we click on Blame then GitHub will show us a history of users or contributors who’ve collaborated on the file. This is helpful in determining which user made what modifications to the file. If we click on History then that would open a history of changes/updates made to the file.  This is similar to the type of output we see using the git log command on the command line but with the difference that here we’ll be viewing changes/log pertaining to a single file. If we click on the highlighted pencil then that will open the script in edit mode in GitHub as shown below:

Now here we can make any required changes to the file. Once we’ve made the required changes to the file we need to commit these changes just as we would while working with git on the command line. If we scroll down the editor page we will find two windows where we would type our commit messages as shown in the below screenshot:

The upper window is for typing a single line commit message as we would in the case with using commit -m while working with git on the command line. The lower window is available when we need to type a larger or more detailed commit message. Once we’ve typed an appropriate commit message we need to click on commit changes to save/commit the modifications made to the file.

Now let’s log in to our local system and view the contents of the file say.pl

[sahil@linuxnix perl_scripts_for_training]$ pwd
/home/sahil/perl_scripts_for_training
[sahil@linuxnix perl_scripts_for_training]$
[sahil@linuxnix perl_scripts_for_training]$ cat say.pl
#!/usr/bin/perl -w

######################################
#Author: Sahil Suri
#Date:
#Purpose:
#version:
######################################

$|=1;
use strict;

use 5.010;

say "Hello World";

As you can see the version of the file available in our local git repository does not have the updates we made to the file when we edited the file in GitHub. Now in order to synchronize the changes made to the file on GitHub with our local git repository we use the git pull command as shown below:

[sahil@linuxnix perl_scripts_for_training]$ git pull origin master
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:sahilsuri007/perl_scripts_for_training
* branch master -> FETCH_HEAD
Updating 9e68102..d619327
Fast-forward
say.pl | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

The output of the above command clearly mentions that the file say.pl was edited and there were three insertions.

Now let’s view the contents of the file again:

[sahil@linuxnix perl_scripts_for_training]$ cat say.pl
#!/usr/bin/perl -w

######################################
#Author: Sahil Suri
#Date: 26/06/2018
#Purpose: Say Hello World
#version: v1.1
######################################

$|=1;
use strict;

use 5.010;

say "Hello World";

The above output shows that the file say.pl has been updated in our local git repository and the changes have been synced with the version of the file available on GitHub.

If we run the git log command within this repository, we find that the commit message we added while making changes to the file say.pl has been added to the git log output as shown below:

[sahil@linuxnix perl_scripts_for_training]$ git log
commit d619327a96a2043b9c177cf0954c8e3e37f5adfe
Author: sahilsuri007 <40155596+sahilsuri007@users.noreply.github.com>
Date: Tue Jun 26 17:10:49 2018 +0530

Modified metadeta for this script say.pl

commit 9e68102f2e622ddd27af211a3064aca7704bbf4b
Author: Sahil Suri <sahildrive007@gmail.com>
Date: Tue Jun 26 22:00:03 2018 +0530

add file testfile

commit 7c578514cf455a20781f2b7902ea4f1ea940b96d
Author: Sahil Suri <sahildrive007@gmail.com>
Date: Tue Jun 12 09:43:28 2018 +0530

A repository of basic Perl scripts to be used as examples in the training

Conclusion

In this article, we demonstrated how we could modify files from within our GitHub account and then synchronize the modifications with the git repository on our local system. We hope that you found this article to be helpful and we look forward towards your suggestions and feedback.

The following two tabs change content below.

Sahil Suri

He started his career in IT in 2011 as a system administrator. He has since worked with HP-UX, Solaris and Linux operating systems along with exposure to high availability and virtualization solutions. He has a keen interest in shell, Python and Perl scripting and is learning the ropes on AWS cloud, DevOps tools, and methodologies. He enjoys sharing the knowledge he's gained over the years with the rest of the community.