Pair programming? Need directions to create a new repository in GitHub and pull from it? Walk through a typical workflow here.

Phong Lo
4 min readApr 8, 2021
Photo by Alvaro Reyes on Unsplash

You recently got paired with a partner to build a project. You’re probably building a frontend and/or a backend. Perhaps, even adding majestic styling to your web application using CSS! It’s towards the end of the day and you both are satisfied with your progress, but you guys are now lost on how to push up your repository to GitHub.

Follow the steps I take below! I’m a visual person, so I love sharing a step-by-step guide using photos.

Uh-oh, how do we create a new repository on GitHub?

Assuming you’ve initialized a git repository in your terminal by running the git command of git init in your command line and creating a git branch by running the git command git checkout -b “your-branch-name”, read the directions below.

1.Login into GitHub and under the Repositories tab, click on “New”. It will route you to a “Create a new repository” page.

2. First, enter your repository name. Second, you can set your repository to public or private. Lastly, to avoid errors, do not initialize the README, gitignore, and license file. These files can be added after your project. Click on “Create repository”.

3.Go into your terminal and make sure you are in your working branch. Copy and paste the below git commands in your terminal and press enter.

4. Congratulations! You added your project to your GitHub repository you had just created!

Next, the most important part is to commit any changes you made to your project and push those changes up to GitHub. Run the following Git commands in this order:

git add .git commit — m “your message here”git push origin HEAD

You should see your updated code in GitHub within seconds! So cool, right?

Make sure to add your partner as a collaborator in GitHub. To do this, go to Settings, Manage Access, and Invite a collaborator by entering their GitHub username (picture below for reference). Your partner should receive an invite via email or a notification from GitHub where she/he can accept access to the repository.

BUT NOT SO FAST!

Assuming your partner was the one who pushed up the project to his/her GitHub and added you as a collaborator— you’ll need to pull that repository from GitHub and have it locally stored onto your computer. This is incredibly helpful, especially in the event, your partner is out sick, on vacation, or whatever the case may be. This is where git clone and git pull comes in!

How do I pull my project from my partners’ GitHub?

Excellent question! First, you want to clone the repository to your local computer and cd into it. For context, I use the SSH remote URL for cloning repos. Also, make sure you’re on the main branch. Like so:

git clone <GitHub repo remote URL here>cd <repo name>git checkout main

Next, you’ll want to pull the remote repository so that it fetches all of the code from it and then merges it to your main branch. Make your new branch. Like so:

git pull origin maingit checkout -b “new-branch-name”

You can now make changes or add code to your project! When you’re done, you’ll…

git add .git commit -m “brief description of what changes/add-ons you did”git push origin HEAD

…to push up your changes from your new branch to GitHub. You will then create a pull request on GitHub for your partner to merge your commit to the main branch. Your partner will have to approve the pull request, resolve any existing conflicts, and then merge the pull request.

Final Thoughts

As a new developer, one advice I wished someone would have told me is to always: COMMIT COMMIT COMMIT.

Definitely learn your Git commands in advance. It’s important to commit your work early on. Especially if you want to record and see the changes you’ve made throughout your project.

Remember, Git is a tool that keeps track of your local repository changes. If mistakes happen, developers can rollback to their previous code. GitHub, on the other hand, is a remote site or a service to host your Git repositories.

I hope this helps you during pair programming! Thank you for stopping by!

Resources

A helpful website to learn more about GitHub is to checkout GitHub Docs here: https://docs.github.com/en.

Also helpful to check out Git Docs here: https://git-scm.com/doc.

--

--

Phong Lo
0 Followers

Full Stack Software Engineer Student at Flatiron