| |

Connect Push Commit Pull Your GitHub Repository To Your Local Computer’s Directory

Introduction

Github is a web version control system which is very useful when you are working on various projects or you want to keep track of changes you make to your project over time. It is a very useful tool as you venture into Data Science and Programming

 

Objective

After you have created a few repositories and Github and you can start working on projects, you would prefer to make changes to your code and update the changes on your Github repository without you having to copy and paste large codes from your local computer to Github every now and then.

The purpose of this write up is to guide you through how you connect Github to your local directory on your computer (windows) so you can send your latest code changes to Github

 

What we will be looking

In this article we will look at:

  1. Creating a repository on GitHub
  2. How to link to your GitHub account to your local directory on your computer (and get your repository codes to your local directory
  3. Create a new file on your local directory
  4. Check the status of your local directory with that of  your Github account
  5. Commit changes on your local directory to Github
  6. Finally send the changes to Github

 

 

Creating a GitHub Repository

  1. Go to Github.com, create and account and go to  profile by clicking on the arrow next to your profile icon in the far right hand corner  
  2. On your profile page, click on Repository and then the “New” button to start creating a new repository 
  3. Click on the “New” Button and enter the appropriate details as in the image below and click on “Create Repository” button to create your repository
  4. You will find your newly created repository along these lines

 

Install Git

We will be accessing Github from command line and for us to be able to do that we will need Git which comes with Git Bash ( a Command Line Interface, CLI) that we can use to access our remote GitHub and its repositories.

Download and install  Git from here

 

  1. After installation, open Git Bash
  2.  
  3. Now we will need to connect our Git Bash interface to GitHub
  4. Let’s tell GitHub the name we will like to appear on our Github account everytime we make changes :
  5. Now let’s tell Github what email address we will use for our Github account(it has to be the same email address we used to create our Github account). We will use this command
  6. Now that we are able to talk to Github, let’s try and get access to the “dp” repository we created on GitHub earlier on.
  7. To do that , let’s create a normal folder on our local computer where we will put all the Github dp repository contents. We can call it same name as the Github respository – in this case “dp”
  8. Let’s make a normal directory from our GitBash command line using this syntax

  9. The “~” means your home directory. Which means we are creating a folder called “dp” in our home directory. Of course, you can create it any other place you want on your PC
  10. Now let’s navigate into our newly created directory “dp” by using the command “cd” 
  11. Now you know your “dp” folder is just a normal folder like any other Windows folder. Now, let’s initialize this normal folder to a Github special folder so that both Windows and GitHub will recognise this folder as a folder that Github can communicate with. We will do the following command:

  12. Now if you can visually check the folder you will see a git folder initiated and dropped in the your folder
  13. Now your local dp folder is ready to communicate with GitHub remote repositories
  14. Now lest’s point this our local folder to our GitHub repository. We will do this using this command
  15. Now that we have pointed our local directory to the remote GitHub directory, let’s us get the content of the remote directory to our local directory. There are several methods but let’s use this command

15. Now if you check the local directory it should have the README.md file which was on our remote GitHub repository now inside the local directory

 

Pushing Files to GitHub

Now that we can pull files from GitHub let’s see how we can upload (push ) files to GitHub

16. Let’s create a markdown file just like our README.md  (file with dot md extension) . We will create it from the command line and give it the name:  dpFile.md. We will use this command

17. This file will be created in your  local dp folder and you can use any text editor like Notepad, Notepad++ to edit it

18. Now that we have added a new file to our local directory let’s see the latest status of our local directory in relation to our remote GitHub directory.  We will use the command below:

19. You can see that Git says, there is a untracked file, which means there is a file in our local folder which our remote directory knows nothing about, hence we will need to notify our remote GitHub that we have some files in our local directory which we may send to it in future. In other words, we need to align this new file in the index of files which can be uploaded to GitHub remote directory. We will use the command

20. Now let’s check the status again

21. Now GitHub is aware of our new File being added to our local directory.

22. Now we have to have make this new file or changes to the local directory “permanent” ( in other words accept or save the changes) and we will use the commit command as follows:

 

23. Now let’s upload our changes to our remote GitHub directory . We will use the push command as follows

 

24. Now if you check your remote GitHub “dp” repository you should see the new dpFile.md uploaded to the repository 

 

Congratulations! You have uploaded your local changes and New Files to your Remote GitHub account.

If you have any questions or comments please leave in the comment box below

 

Summary of what you learnt

In this article you learnt about

  1. Creating a GitHub repository and initiating a README.md file
  2. Creating a local directory and making it GitHub ready and linking it to your GitHub remote repository
  3. Creating a new file on your local directory
  4. Checking the status of your local directory with respect to your remote GitHub repository
  5. Committing changes on your local directory
  6. Finally sending the changes to your remote Github account

Do you find or think GitHub is really useful and needed in our studies and work career? How has it helped you?

I will like to hear your experience in the comment box below.

 

Resources:

  1. Data Tool on Youtube has some really good tutorials on GitHub
  2. A good and comprehensive GitHub tutorial for beginners
  3. Download Git

 

Want more information like this?

Similar Posts

  • | |

    Running a Classification Tree – Decision Tree – Data Analysis and Intrepretation

    Overview My research work deals with Ghana, a country from the Gapminder dataset as has already been discussed from the beginning and progression through this course. Picture Of My Final Decision Tree Outputted From My Python Program   The variables in my observation dataset are all quantitative. For the purposes of this assignment, I have binned…

  • |

    Python List Comprehension Dictionary Set Comprehension and For Loops

    This is a guide on Python List comprehension. List comprehension is a great way to write simple and easy to read Python codes. You can use it dictionaries and sets as well.   Credits to  Corey Schafer , creator of Python course materials. lets create a list In [115]:

      Out[115]:

    lets grab all the…

  • | | | | |

    Java Python R SQL Excel Compared Similarities For Data Science and Data Analytics – The Basics

    If you have ever worked with Java, Python, R, SQL, Excel and other Languages on a varied Data Science or Data Analytics projects, you will realise that all these languages have similar syntaxes, or at least, can achieve the same objective with very similar codes.   Below is a comparison and similarities of these various tools…

  • |

    Running a Chi-Square Test of Independence – Data Analysis and Intrepretation

    Running a Chi-Square Test of Independence For the purpose of running Chi Square Test of Independence on the Gapminder dataset I am working on, as indicated in the assignment instruction, I will have to categorize some of my Gapminder quantitative variables into categorical variables. In this sense, I have added another quantitative variable from the Gapminder…

  • |

    Quick Example and Walk-Through JSON with Python

    This is a quick to create a dictionary object , write it to a JSON file and then read back the file and convert it to a dictionary and access the items in the dictionary. Credit to : codebasics.  You can check him out on Youtube In [3]:

      In [6]:

      Out[6]:

    In [14]:…

  • | |

    Testing a Basic Linear Regression Model – Data Analysis and Intrepretation

    Testing a Basic Linear Regression Model Background My research work deals with Ghana, a country from the Gapminder dataset as has already been discussed from the beginning and progression through this course.     1)     Program  Code and Output

           #####################     OUTPUT BEGIN  #####################     Axes(0.125,0.125;0.775×0.775) Describe the centered…

Leave a Reply

Your email address will not be published. Required fields are marked *