Git-Pong — Collaborating using version control

This exercise is designed to give you experience in working in teams on code, which is very common in development. This is a crucial and important concept for all developers working on teams and one that you will want to to master.

These are the steps you and your pairing partner need to take in order to be able to share code using GitHub. This is a concept that we refer to as Git Pong

First, let’s set a few rules.

  1. A Git repository is a set of files and folders that are under version control. Most often it is located on your local computer
  2. GitHub is a cloud service that, among other things, lets us store git repositories.
  3. You need to connect your local git repository with GitHub by adding a remote on your computer.
  4. You can have several remotes added to your git repository.

We assume that we have two users (User 1 and User 2) that want to work on the same code base. What follows is one possible workflow (one that I want you to master before we introduce others).

Please follow the instructions carefully.

User 1 — Setup

Visit your GitHub account and create a new repository. Call it git_pong_demo.

Copy the url to the repository (either the HTTPS or GIT address, you can choose any of them but remember that the GIT address requires you to have your SSH keys set up).

Head over to your Terminal and clone the repository to your computer with the following command.

$ git clone (the url you copied)

A new folder called git_pong_demo is created on your computer. Make sure you cd into that folder.

$ cd git_pong_demo

Create a new file called README.md

$ touch README.md

Open it in your editor and add some content.

##Learning Git Pong
I need to master this so I can be a good team member.

In your Terminal, make sure you go through the two steps needed for updating your repo. These are:

Add files to git $ git add . or $ git add README.md

Commit files

$ git commit -am "added README with content"

Push up to GitHub in order to store the changes in the cloud.

$ git push origin master

User 2 — Get in the loop

At this stage we can focus on User 2. These steps needs to be completed so you can have access to User 1’s code (Note that you need to be logged in to GitHub)

Ask User 1 for the url to his repository. Go to that url using your browser.

Locate and click the Fork button on User 1's repository. That will make a copy (a fork) to your GitHub account and you will be redirected to that copied repository.

Copy the url to the repository (either the HTTPS or GIT adress, you can choose any of them but remember that the GIT address requires you to have your SSH keys set up).

Head over to your terminal and clone the repository to your computer with the following command.

$ git clone (the url you copied)

A new folder called git_pong_demo is created on your computer. Make sure you cd into that folder.

$ cd git_pong_demo

Open the README.md file in your editor and add some changes.

##Learning Git Pong 
I need to master this so I can be a good team member. GitPong allows for collaboration without geographical boundaries. It can be used when teams are co-located as well when they are distributed.

In your Terminal, commit your changes using.

$ git commit -am "updated README with info about GitPong"

Push up to GitHub in order to store the changes in the cloud.

$ git push origin master

User 1 — Pong back

Now, let’s focus on User 1 again and how he or she can get the changes User 2 just made on his computer and stored on his GitHub account.

Ask User 2 for the url to his repository. Visit that url using your browser.

Copy the url to the repository (either the HTTPS or GIT address, you can choose any of them but remember that the GIT address requires you to have your SSH keys set up).

Head over to your Terminal and add User 2’s GitHub repo as a second remote

$ git remote add (User 2's GitHub name) (the url you copied)

For the rest of this walkthrough we’ll assume that User 2’s GitHub name is user_2

Tell git to get the information about User 2’s repository that is stored on GitHub with this command.

$ git fetch user_2

That will result in some terminal output. Read it carefully the first time you try this. If there is an error, git will notify you.Any errors you will get are most often caused by a typo — make sure you spell everything correctly.

Tell git to add the changes User 2 made using the pull command.

$ git pull user_2 master

Now you will see that the changes that User 2 made are being copied to your computer. Open up the README.md file in your editor and see for yourself.

Now, add some new content to the README.md file.

##Learning Git Pong 
I need to master this so I can be a good team member. GitPong allows for collaboration without geographical boundaries. It can be used when teams are co-located as well when they are distributed.
**Another cool thing I just learned is Markdown!***

In your Terminal, commit your changes using.

$ git commit -am "updated README with info about GitPong"

Push up to GitHub in order to store the changes in the cloud.

$ git push origin master

User 2 — again…

Let’s focus on User 2 again.

Ask User 1 for the url to his repository again (if you don’t remember it form the last time you used it).Visit that url using your browser.

Copy the url to the repository (either the HTTPS or GIT address, you can choose any of them but remember that the GIT address requires you to have your SSH keys set up).

Head over to your Terminal and add User 1’s GitHub repo as a second remote. For the rest of this walkthrough we'll assume that User 1's GitHub name is user_1

$ git remote add user_1 (the url you copied)

Tell git to get the information about User 1’s repository that is stored on GitHub with this command.

$ git fetch user_1

That will result in some terminal output. Read it carefully the first time you try this. If there is an error, git will notify you.Again, the errors you will get are most often caused by a typo — make sure you spell everything correctly.

Tell git to add the changes User 1 made using the pull command.

$ git pull user_1 master

Now you will see that the changes that User 1 made are being copied to your computer. Open up the README.md file in your editor and see for yourself.

Now, you can add some more changes to the file. Add whatever content you want.

In your Terminal, commit your changes using.

$ git commit -am "updated README with more info about GitPong"

Push up to GitHub in order to store the changes in the cloud.

$ git push origin master

Wrap up

And so on, and so on…

Now, both User 1 and User 2 have each others repositories added as remotes and are able to practice Git Pong. All changes that they make are made on their local computers and pushed up to their respective GitHub accounts. In this way they can keep their own versions of the repository and choose to get the other users changes if they want to. In order to get the changes that the other user have made, they have to make a git pull.

By practicing these steps you will lay the foundation for team collaboration in your development projects.

— -

I work as Head Coach at Craft Academy — a Tech Education Provider that aims to bring new talent to the market and help to solve the shortage of tech workers. We are founded on the belief that modern development standards, agile methodologies and business skills are fundamental for ITC professionals. Our primary service is a 12-week coding bootcamp designed to provide individuals with a foundation of skills that allows them to enter the industry as junior developers.

With that foundation, our learners find employment in various industries or start their own businesses that bring new innovations to the market.

Would you like to know more about what we do? Follow us here on Medium, Facebook, Twitter or visit our website.