My Most Used Git Commands on Open Source Projects
Learn more about one dev's favorite Git commands for OS projects.
Join the DZone community and get the full member experience.Join For Free
The basic step when committing to open source projects is to fork the project. Then the process is easy you create your branch and you make a pull request. However, from time to time, you need to adjust your branch based on the latest changes.
You may also like: Top 20 Git Commands With Examples
This is how you sync your fork to the original one.
git fetch upstream git checkout master git merge upstream/master
This is pretty easy, but you might want something more than just synchronizing with the original repository.
For example, there might be a pull request that never got merged for various reasons and you want to pick up from where it was left.
The first step is to add the repository needed
git remote add $remote_repo_identifier $remote_repo_url
So we just added another remote to our repository.
The next step is to fetch the branches from the remote.
git fetch $remote_repo_identifier
Then you can switch to the branch of your choice, continue to make a new branch, and continue with a pull request.
git fetch $remote_branch
Remove the upstream:
git remote remove $remote_repo_identifier
And set the upstream to your original one:
git push --set-upstream origin $remote_branch
There you have it! Hope you enjoyed!
Published at DZone with permission of Emmanouil Gkatziouras, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.