DEV Community

Leyang Yu
Leyang Yu

Posted on

Working With Remotes in Git

Intro

This week in my open source development course, we learned about how to work with git remotes, such as how to fetch or pull and how to merge branches. I had the chance to work with two fellow classmates, Irene Park whose repo I worked on and Francesco Menghi who worked on my repo.

Making Changes to Another Repo

I was really excited to work on Irene's repo as although I have some experience working in Java, it has been a while since I last coded in the language. The feature I wanted to add was the option for a --config/-c flag in the command line so that rather than passing a long list of command line arguments, a user could pass a config file specifying all arguments. These were some of the main changes I made to her program

  1. Added json-simple as a dependency to parse JSON files
  2. Updated the code to check for the --config/-c flag in the command line. If the flag and config file exist, parse the file to get the input and output values.
  3. Updated the documentation

I created an issue and a draft pull request which I updated gradually, so that Irene could see any significant changes I made along the way. Although the coding part was not too difficult, setting up the environment for Java in Visual Studio Code, adding the json-simple dependency, and creating the executable jar file were all new to me and took me a bit of time to figure out. I communicated my changes to Irene via Slack and my changes were successfully merged into her repo.

Accepting Changes to My Repo

I also received an issue and pull request for my repo. I had a lot of great discussion with Francesco and he mentioned that he was "really seeing the benefit of code review now" after I tested his changes and made several suggestions. I was able to test his code by adding his repo as a remote to my local repo and creating a tracking branch. From there, I could pull any changes that he made and continue testing. After going back and forth a few times until all the problems were fixed, I merged Francesco's branch with my main branch. I intended to merge it from the command line but accidentally did so through the GitHub interface. Thankfully, Francesco helped me out by creating another PR and I learned more about fetching and merging remotes through running the commands in the command line.

Working with Git

I found the process of using Git to be very straightforward and really useful, as it allowed me to collaborate with others across upstream/downstream repos. Although I have been using Git for a while, the concept of multiple remotes is new to me as I have never really worked with forked repos before so this was a great exercise to learn how to do so. I learned a lot about best practices for using remotes, which I will continue using in the future.

Top comments (0)