Git/C3/Working-with-Remote-Repositories/English

From Script | Spoken-Tutorial
Jump to: navigation, search

Title of script: Working with Remote Repositories

Author: Priya K

Keywords: Video tutorial, Git, GitHub, repository, remote repository, clone, pull data, push data


Visual cue
Narration
Slide 1:

Working with Remote Repository

Welcome to the spoken tutorial on Working with Remote Repositories.
Slide 2:Learning Objectives
  • What is Remote repository
  • How to synchronize data to the Remote repository


In this tutorial, we will learn -


  • What is Remote repository and
  • How to synchronize data to the Remote repository


Slide 3:

System requirement

For this tutorial, I am using

  • Ubuntu Linux 14.04 OS
  • Git 2.3.2
  • gedit Text Editor
  • Firefox web browser


For this tutorial, I am using
  • Ubuntu Linux 14.04
  • Git 2.3.2
  • gedit Text Editor and
  • Firefox web browser

You can use any editor and web browser of your choice.

Slide 4:

Pre-requisites

  • Working internet connection
  • You should have knowledge of basics of Git commands
  • If not, for relevant Git tutorials please visit http://spoken-tutorial.org


For this tutorial, you will need a working Internet connection.
  • You should also have knowledge of basics of Git commands.
  • If not, for relevant Git tutorials, please visit the link shown.


Slide 5:

Remote repository

  • A repository hosted on the internet is called Remote repository
  • Using this centralized repository, people can collaborate from anywhere, anytime


First let us understand what is a Remote repository.


  • A repository which is hosted on the internet or any network is called Remote repository.
  • Using this centralized repository, people can collaborate on a project from anywhere in the world, at anytime.


Slide 6:

Working with Remote repository[[Image:]]

Say, for example, there are 3 users who want to work jointly in the same repository.


Git allows them to take a copy of the Remote repository into their local system.


This will be done using clone command.


Then they can work offline with the local repository.


Once the work is satisfied, they have to synchronize it back to the main repository.


This will be done using Push and pull commands.


You will understand the full process at the end of this tutorial.


<<PAUSE>>

Open GitHub repository First we will open our GitHub repository which we created earlier.
Point to URL In the right side, we can see the URL of this repository.
Copy the URL Let’s copy this URL.


We are going to make a copy of this repository using the URL to create a local repository.

Open terminal and type cd Desktop and Enter, Type ls and Enter


Highlight the folders User1 and User2

Let’s open the terminal.


Let us understand now how two users can work in the same Remote repository.


For this, I have already created two directories named User1 and User2 on my Desktop.


Please do so on your Desktop also.

Type cd User1 and Enter


Click on File menu and select Open Tab.


Type cd User2 and Enter

In the same terminal, I will open the directories in 2 different tabs.


In the first tab, type cd User1


To open second tab, click on File menu and select Open Tab.


In the second tab, type cd User2

Click on the tab User1 Let us go to the tab User1.
Type git clone URL .


Now let us make a copy of the Remote repository.


Type git space clone and then paste the copied URL space and type a dot at the end of this command.

Highlight . (dot) Dot indicates that we are going to copy the repository inside the same directory i.e. User1.


Otherwise, it will create a new directory with the repository name as stories.

Press Enter Now press Enter.
The clone command will copy the whole central folder and make it as a local repository.
Type ls and Enter Type ls.


You can see that the content of the Remote repository is copied here.

Type git config user.name “priya-spoken1”

git config user.email “priyaspoken1@gmail.com”

Next, I will change the user name and email id of this repository for better understanding.


I have already created two more GitHub users - priya-spoken1 and kaushik-spoken - for demonstration purpose.


I will use them here.

Type git log --oneline


Show the commits of the remote repository

Let us check the Git log.


You can see the same commits of the Remote repository.

Click on the tab User2

git clone URL .

Likewise, I will clone the repository inside the directory User2 in the second tab.
git config user.name “kaushik-spoken

git config user.email “kaushikspoken@gmail.com”

Here also I will change the user name and email id as I did earlier for User1.


<<PAUSE>>

Next, let us understand how these users will work in the Remote repository.
Click on User1 tab

Type ls and Enter

Let’s check the directory content of User1.
Let’s say, User1 will be working on a file named lion-and-mouse.html.
Type gedit lion-and-mouse.html and Enter To create the file, type gedit lion-and-mouse.html.
Copy and paste the code into the file I will copy and paste some text into this file, from my Writer document, which I had saved earlier.

Likewise, you can add some content in your file.

Type git add lion-and-mouse.html and Enter Let's add the file into the staging area.


Type git add lion-and-mouse.html

Type git commit -m “Added lion-and-mouse.html” and Enter Next let us commit the newly added file.


Type git commit hyphen m within quotes Added lion-and-mouse.html.

Next we have to synchronize the local repository with the main Remote repository.


Before synchronizing the repository, we will learn about remotes.


<<PAUSE>>

Slide 7:

Remote

  • The URL of a remote repository is called Remote
  • We can give a nickname to the URL.
  • It will be useful when we work on many remote repositories
  • When we synchronize the repository, we can simply use the nickname
  • The default nickname is always origin.


* The URL of a Remote repository is called Remote.
  • We can give a nickname to the URL.
  • It will be useful when we work on many Remote repositories.
  • When we synchronize the repository, we can simply use the nickname, instead of typing the full URL.
  • The default nickname of a Remote is always origin.


Now let us learn how to add a Remote.
Switch to terminal


Type git remote and Enter


Highlight origin

Switch back to our terminal.


Type git remote


You can see that the default Remote name is origin.

Type git remote add stories URL


Press Enter

Next let us see how to add a nickname to the Remote.


Type git remote add stories and type the URL of the Remote repository.


Here I will name the Remote as stories that is the Remote repository name.


Now press Enter key.

Type git remote and Enter


Highlight stories

Again to check the Remote list, type git remote.


You can see that the Remote is added to the list.


<<PAUSE>>

Type git push stories master Now we will synchronize the local repository with the main Remote repository.


To do so, type git push stories master

Here stories is the Remote name and master is the branch where we update the changes.
Press Enter Now press Enter.
Type username as priya-spoken1


I will type priya-spoken1 as username of User1 and press Enter.
Type password Type the corresponding password of User1.
Recall that I created this username earlier for demonstration purpose.


Please use your username and password here.

Highlight unable to access It throws an error unable to access.
Why did this error occur?


This is because we don't have access to the Remote repository.

So now, let us learn how to give access permission to the contributors.
Switch back to GitHub repository Switch back to GitHub repository.
Click on Settings tab Click on the last tab - Settings - in the top panel.
Click on Collaborators link


Type the password

Then click on Collaborators link in the left side box.


Type your GitHub account password for confirmation.

Point to the text box Here in the text box, we can add the names of the collaborators.


Understand that anyone can clone this GitHub repository.


But the people who we add as collaborator, can push to the repository.

Tyoe priya-spoken1


Now I will add the two users priya-spoken1 and kaushik-spoken.


You can see that the user name is listed when I type in the text box.

Click on Add Collaborator button Click on Add Collaborator button to add the user as collaborator.
Type kaushik-spoken I will also add the other user kaushik-spoken.
Highlighted the users You can see here the added names are listed.
Now we will try to push into the Remote repository.
Switch back to the terminal Switch back to the terminal.
Type git push stories master and Enter Type git push stories master
Type priya-spoken1 and password


Give the username and password of the user who has the access to the repository.
Highlight the output You can see that we have pushed it successfully.
Next, let us check the GitHub repository to see whether our changes are updated.
Switch to the GitHub repository. Switch back to the GitHub repository.
Click on the Code tab Click on the Code tab.
Click on Commits link Let’s check the commit list.
Point to Added lion-and-mouse.html You can see that the commit of the collaborator is listed here.


<<PAUSE>>

Click on User2 tab in the terminal Next, let us learn how User2 can collaborate with the Remote repository.
Switch back to the terminal Switch back to the terminal.
Let’s say, User2 is working on a file named friends.html.
Type gedit friends.html To create the file, type gedit friends.html.
Copy-paste the code I will copy and paste some text into this file, from my Writer document.

Likewise, you can add some content into your file.

Type git add friends.html Let's add the file into the staging area.
Type git commit hyphen m “Added friends.html” and Enter Next let’s commit the newly added file.


Type git commit hyphen m within quotes Added friends.html.

Type git push origin master Next we have to synchronize the local repository with the main Remote repository.


Type git push origin master

Highlight origin


Remember that we didn't add Remote to this local repository.


So here we are using the default Remote name origin.

Press Enter Now press Enter.


Type the GitHub username and password of the User2.

Highlight failed to push It throws an error which says failed to push.
Highlight the remote contains work that you do not have locally Also, it shows the reason for the error: the remote contains work that you do not have locally.


Remember that the User1 has pushed a commit earlier.


But User2 doesn't have the work of User1 in its local repository.

Highlight 'git pull ...') before pushing again It also gives a suggestion to run git pull command to rectify the error.
So first, we have to pull down the work of User1 and incorporate it into the User2’s local repository.


Let’s do it now.

Type git pull origin master and Enter Type git pull origin master
Press ctrl + x First it will fetch the data from Remote repository then merge it with the local repository.


So it opens an editor to give a message for merging.


Let’s keep the same message and close the editor by pressing Ctrl + X.

Type git push origin master and Enter Now again, we will try to push the data.


Type git push origin master

Give the username and password of User2.
You can see that we could successfully push the data now.
Switch to the GitHub repository. Next let us check the GitHub repository to see whether our changes are updated.


Switch back to the GitHub repository.

Click on the repository name Stories Click on the repository name Stories.
Highlight friends.html You can see that the file friends.html is now added to the repository.
Click on Commits link


Point to Added friends.html

Let’s check the commit list now.


You can see that the commit of User2 is also listed here.


<<PAUSE>>

With this, we come to the end of this tutorial.
Slide 8:

Summary

  • What is Remote repository
  • How to synchronize data to the Remote repository


Let us summarize.


In this tutorial, we have learnt -

  • What is Remote repository and
  • How to synchronize data to the Remote repository


Slide 9:

Assignment

  • Create one more user named User3
  • Clone data for User3
  • Start working on User3 local repository
  • Try to push data from User3


As an assignment
  • Create one more user named User3
  • Clone data for User3
  • Start working on the local repository of User3 and
  • Try to push data from User3


Slide 10:

Acknowledgement


The video at the following link summarises the Spoken Tutorial project.


Please download and watch it.

Slide 11:

Spoken Tutorial Workshops


The Spoken Tutorial Project Team conducts workshops and gives certificates to those who pass online tests.


For more details, please write to us.

Slide 12:

Acknowledgement


Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.


More information on this Mission is available at the following link.

This is Priya from IIT Bombay. Thanks for joining.

Contributors and Content Editors

Priyacst