Syncing local git branched repo branches with changes from the remote original

I found a lot of q about synchronizing a forked git repository with the original remote repository, but none of them apply to my exact problem.

Suppose I forked a project with the remote name upstream, my fork name is the beginning. I have a master and branch dev locally, which is a master track and dev origin.

While I am not making any changes to my forked repo, I know that I can synchronize the forked repo by origin using upstream / master

git checkout master git pull upstream master git push origin master 

So far so good. But now I am working on my local dev branch, and as soon as I finish, I would like to merge it with my local master. But first, I would update my local master with upstream changes

 git checkout master git pull upstream master git push origin master 

First question (s) : Is that right? But what should I do with my local branch? Restore it on my updated host before merging it into a local master or try combining it without rebooting? Or should I try to keep my local developer in sync with the upstream / downstream all the time, occasionally upstream / downstream?

Once this is done, I would

 git push origin master 

and remove the dev branch, locally and at the beginning. But now my host (locally and by origin) deviates from the upstream / main by the changes made by my local developer.

Second question : What is the right way to synchronize with the upstream / downstream? I'm still just doing

 git checkout master git pull upstream master git push origin master 

or something else recommended here (for example, some form of reinstallation)? If I created the dev branch again, would I apply the same strategy that was used for the first question, or is something else applicable?

Thank you for your help!

+4
source share
1 answer

Question 1:

I would say that in any case, everything is in order. In my experience, something like this usually works very well:

  • When you merge from the upstream / lead to the local / master, it makes sense to reload local / dev.
  • If you reinstall dev when you get changes to master, you reduce the size of the / rebase merge that you have when you want to merge dev back into master.
  • This works as long as you always change the changes from master to dev

Once you are done with dev, you can either reinstall again and then merge to master or simply merge directly to master. You can change the message in a merge commit to indicate what was in your merge.

Question 2:

When merging with the upstream, if you do not have any changes in your local or origin, the mergers will be quick. This basically means that git just stacks upstream commits on top of everything you had and there will be no merging conflicts or anything else.

Because of this, you do not need to reinstall or anything else. As mentioned above, if you are working on something on dev, it might be a good idea to reinstall dev at this point so that you get it more relevant.

At that moment, when you have changes that are different from the upstream, you will have the actual merge and the ability to perform a reinstall if you wish.

Rebuild or drain?

It mainly depends on you and how you like to work, but if you think that it is rebooted, remember that it changes history.

If someone else uses origin / master or origin / dev and you can reinstall it, they might run into some problems when trying to combine their work. Therefore, if a branch is used by no more than one person, you should use merges. Never use rebase (or anything else that changes history) if more than one person is using a branch.

+5
source

All Articles