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

From Script | Spoken-Tutorial
Jump to: navigation, search
Time
Narration
00:01 Welcome to the spoken tutorial on Working with Remote Repositories.
00:06 In this tutorial, we will learn - What is Remote repository and
00:12 How to synchronize data to the Remote repository
00:16 For this tutorial, I am using Ubuntu Linux 14.04
00:22 Git 2.3.2
00:25 gedit Text Editor and
00:28 Firefox web browser
00:30 You can use any editor and web browser of your choice.
00:36 For this tutorial, you will need a working Internet connection.
00:41 You should also have knowledge of basics of Git commands.
00:46 If not, for relevant Git tutorials, please visit the link shown.
00:52 First let us understand what is a Remote repository.
00:56 A repository which is hosted on the internet or any network is called Remote repository.
01:04 Using this centralized repository, people can collaborate on a project from anywhere in the world, at anytime.
01:13 Say, for example, there are 3 users who want to work jointly in the same repository.
01:21 Git allows them to take a copy of the Remote repository into their local system.
01:28 This will be done using clone command.
01:31 Then they can work offline with the local repository.
01:36 Once the work is satisfied, they have to synchronize it back to the main repository.
01:43 This will be done using Push and pull commands.
01:48 You will understand the full process at the end of this tutorial.
01:53 First we will open our GitHub repository which we created earlier.
01:59 In the right side, we can see the URL of this repository.
02:05 Let’s copy this URL.
02:08 We are going to make a copy of this repository using the URL to create a local repository.
02:16 Let’s open the terminal.
02:18 Let us understand now how two users can work in the same Remote repository.
02:24 For this, I have already created two directories named User1 and User2 on my Desktop.
02:33 Please do so on your Desktop also.
02:36 In the same terminal, I will open the directories in 2 different tabs.
02:43 In the first tab, type cd space User1
02:49 To open second tab, click on File menu and select Open Tab.
02:55 In the second tab, type cd User2
03:00 Let us go to the tab User1.
03:03 Now let us make a copy of the Remote repository.
03:08 Type git space clone and then paste the copied URL space and type a dot at the end of this command.
03:17 Dot indicates that we are going to copy the repository inside the same directory i.e. User1.
03:25 Otherwise, it will create a new directory with the repository name as stories.
03:31 Now press Enter.
03:33 The clone command will copy the whole central folder and make it as a local repository.
03:40 Type ls. You can see that the content of the Remote repository is copied here.
03:48 Next, I will change the user name and email id of this repository for better understanding.
03:55 I have already created two more GitHub users - priya-spoken1 and kaushik-spoken - for demonstration purpose.
04:04 I will use them here.
04:14 Let us check the Git log.
04:16 You can see the same commits of the Remote repository.
04:21 Likewise, I will clone the repository inside the directory User2 in the second tab.
04:28 Here also I will change the user name and email id as I did earlier for User1.
04:35 Next, let us understand how these users will work in the Remote repository.
04:41 Let’s say, User1 will be working on a file named lion-and-mouse.html.
04:48 To create the file, type gedit lion-and-mouse.html.
04:54 I will copy and paste some text into this file, from my Writer document, which I had saved earlier.
05:02 Likewise, you can add some content into your file.
05:06 Let's add the file into the staging area.
05:11 Type git add lion-and-mouse.html
05:17 Next let us commit the newly added file.
05:21 Type git commit hyphen m within quotes Added lion-and-mouse.html.
05:29 Next we have to synchronize the local repository with the main Remote repository.
05:35 Before synchronizing the repository, we will learn about remotes.
05:40 The URL of a Remote repository is called Remote.
05:45 We can give a nickname to the URL.
05:49 It will be useful when we work on many Remote repositories.
05:54 When we synchronize the repository, we can simply use the nickname, instead of typing the full URL.
06:01 The default nickname of a Remote is always origin.
06:06 Now let us learn how to add a Remote.
06:10 Switch back to our terminal.
06:13 Type git remote. You can see that the default Remote name is origin.
06:20 Next let us see how to add a nickname to the Remote.
06:25 Type git remote add stories and type the URL of the Remote repository.
06:32 Here I will name the Remote as stories that is the Remote repository name.
06:38 Now press Enter key.
06:41 Again to check the Remote list, type git remote.
06:46 You can see that the Remote is added to the list.
06:50 Now we will synchronize the local repository with the main Remote repository.
06:55 To do so, type git push stories master
07:00 Here stories is the Remote name and master is the branch where we update the changes.
07:07 Now press Enter.
07:09 I will type priya-spoken1 as username of User1 and press Enter.
07:17 Type the corresponding password of User1.
07:21 Recall that I created this username earlier for demonstration purpose.
07:27 Please use your username and password here.
07:31 It throws an error unable to access.
07:35 Why did this error occur? This is because we don't have access to the Remote repository.
07:42 So now, let us learn how to give access permission to the contributors.
07:48 Switch back to GitHub repository.
07:51 Click on the last tab - Settings - in the top panel.
07:55 Then click on Collaborators link in the left side box.
08:00 Type your GitHub account password for confirmation.
08:04 Here in the text box, we can add the names of the collaborators.
08:10 Understand that anyone can clone this GitHub repository.
08:15 But the people who we add as collaborator, can push to the repository.
08:21 Now I will add the two users priya-spoken1 and kaushik-spoken.
08:27 You can see that the user name is listed when I type in the text box.
08:33 Click on Add Collaborator button to add the user as collaborator.
08:38 I will also add the other user kaushik-spoken.
08:43 You can see here the added names are listed.
08:47 Now we will try to push into the Remote repository.
08:51 Switch back to terminal.
08:54 Type git push stories master
08:58 Give the username and password of the user who has the access to the repository.
09:04 You can see that we have pushed it successfully.
09:08 Next, let us check the GitHub repository to see whether our changes are updated.
09:14 Switch back to the GitHub repository.
09:17 Click on the Code tab.
09:20 Let’s check the commit list.
09:23 You can see that the commit of the collaborator is listed here.
09:28 Next, let us learn how User2 can collaborate with the Remote repository.
09:34 Switch back to the terminal.
09:37 Let’s say, User2 is working on a file named friends.html.
09:43 To create the file, type gedit friends.html.
09:49 I will copy and paste some text into this file, from my Writer document.
09:54 Likewise, you can add some content into your file.
09:59 Let's add the file into the staging area.
10:03 Next let’s commit the newly added file.
10:07 Type git commit hyphen m within quotes Added friends.html.
10:15 Next we have to synchronize the local repository with the main Remote repository.
10:21 Type git push origin master
10:25 Remember that we didn't add Remote to this local repository.
10:30 So here we are using the default Remote name origin.
10:34 Now press Enter.
10:37 Type the GitHub username and password of the User2.
10:42 It throws an error which says failed to push.
10:46 Also, it shows the reason for the error: the remote contains work that you do not have locally.
10:53 Remember that the User1 has pushed a commit earlier.
10:58 But User2 doesn't have the work of User1 in its local repository.
11:04 It also gives a suggestion to run git pull command to rectify the error.
11:10 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.
11:21 Type git pull origin master
11:25 First it will fetch the data from Remote repository then merge it with the local repository.
11:32 So it opens an editor to give a message for merging.
11:36 Let’s keep the same message and close the editor by pressing Ctrl + X.
11:42 Now again, we will try to push the data. Type git push origin master
11:50 Give the username and password of User2.
11:54 You can see that we could successfully push the data now.
11:59 Next let us check the GitHub repository to see whether our changes are updated.
12:05 Switch back to the GitHub repository.
12:08 Click on the repository name Stories.
12:12 You can see that the file friends.html is now added to the repository.
12:18 Let’s check the commit list now.
12:21 You can see that the commit of User2 is also listed here.
12:26 With this, we come to the end of this tutorial.
12:30 Let us summarize. In this tutorial, we have learnt -
12:35 What is Remote repository and
12:38 How to synchronize data to the Remote repository
12:42 As an assignment, Create one more user named User3
12:47 Clone data for User3
12:50 Start working on the local repository of User3 and
12:54 Try to push data from User3
12:58 The video at the following link summarises the Spoken Tutorial project.
13:03 Please download and watch it.
13:05 The Spoken Tutorial Project Team conducts workshops and gives certificates to those who pass online tests.
13:12 For more details, please write to us.
13:16 Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
13:22 More information on this Mission is available at the following link.
13:27 This is Priya from IIT Bombay. Thanks for joining.

Contributors and Content Editors

PoojaMoolya