Newbie open-source contributor here.
I forked the TortoiseGit repository on GitLab, then cloned it on my computer, edited one file, and committed to branch master
.
A few days have passed and I want to update my local working copy with the latest changes from upstream, before pushing to my remote fork and opening a merge request (and of course doing more development/testing etc).
I added a remote called upstream
to my repo and now I'm not sure what would be the recommended action:
git pull
from upstream/master
to my checked-out branch master
git pull --rebase
//git fetch
followed by git rebase
.These are the approaches I found during my research. Unfortunately I could not find a comprehensive review of each, nor a recommendation as to which one is typical practice when working in projects from GitHub, GitLab or even those like the Linux kernel.
I tried methods 1 and 3. Method 1 (pull
) generates a merge commit (--ff-only
is not possible) and my history is, in a way, polluted. It also creates conflicts. Method 3 (rebase
) does neither, but I'm not sure how rebase
behaves after commits are pushed to remote and so I'm afraid it might cause problems going forward.
So there's my question.
Thank you.
Syncing a fork branch from the web UI On GitHub, navigate to the main page of the forked repository that you want to sync with the upstream repository. Select the Sync fork dropdown. Review the details about the commits from the upstream repository, then click Update branch.
Go to your fork, click on Fetch upstream , and then click on Fetch and merge to directly sync your fork with its parent repo. You may also click on the Compare button to compare the changes before merging.
TortoiseGit team member here.
I added a remote called upstream to my repo and now I'm not sure what would be the recommended action:
1. git pull from upstream/master to my checked-out branch master
2. git pull --rebase //
3. git fetch followed by git rebase.
Different team uses different workflow.
See Pro Git (v2) - 5.1 Distributed Git - Distributed Workflows
In TortoiseGit team, we prefer keep the history simple, and contributor usually has the responsibility for resolving the conflicts while rebasing.
So, most of the time, we use "git fetch followed by git rebase", especially when contributing. Then, as you said, creating pull/merge request (by using git push), or updating the pull/merge request (by using git push with force) on GitHub/GitLab.
See How Can I Contribute? and HowToContribute.txt for other detail information.
I forked the TortoiseGit repository on GitLab, then cloned it on my computer, edited one file, and committed to branch master A few days have passed and I want to update my local working copy with the latest changes from upstream
If by upstream you're referring to the main repo, you can
git fetch origin
git rebase origin/master
assuming origin
points to the main repo
Rebasing replays the commits of your current branch (your local master
branch) on top of the branch you're rebasing origin/master
in this case, which is a reference to the current master
branch of origin
.
For example:
master
branch before your commit:
master
branch after your commit:
After a few days, TortoiseGit git commits to origin/master
which now looks like this.
You sync the changes by fetching and rebasing on top of origin/master
. Your local master
branch will now look like this:
I added a remote called upstream to my repo and now I'm not sure what would be the recommended action
then you can simply git push upstream master
to update your fork.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With