{{announcement.body}}
{{announcement.title}}

My Most Used Git Commands on Open Source Projects

DZone 's Guide to

My Most Used Git Commands on Open Source Projects

Learn more about one dev's favorite Git commands for OS projects.

Free Resource

Open source git commands

Learn more about one dev's favorite Git commands for OS projects.

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!

Further Reading

Gitting Started With Git

Top 20 Git Commands With Examples

Useful Git Commands

Topics:
open source ,git ,commands ,os ,shell ,command-line

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}