k25
k25

Reputation: 407

GitHub - merging changes to a branch in different folder from master

I have been using github for quite a while. Now I have multiple branches for a project and also working on a couple of branches at the same time. For every branch I have a folder dedicated to itself and I commit and do a push to respective branches. Now I have a situation where I have to update one of my branches with changes in the master, since I branched before making the changes to the master. Before I do any commit, I created a 'playground' repo and was playing with it. This is the method I follow to merge the changes from my master to the branch and I would like to get all of your opinions on this method - whether it's correct or not and also whether something else has to be done. Of course, I figured out this method using SO, but the answers were in bits and pieces across multiple questions. But just wanted a single point where I could verify what I am doing!

As a side note, while I was looking up for information, I saw that I don't have to create separate folders for the branches and can just use 1 folder. But I like this approach better - maintaining separate folders.

Here is what I do:

# make some changes to master and commit it

git add .
git commit -m 'at last!'
git push -u origin master

# cd to the branch

git pull

git merge origin/master

# now commit to branch

git add .

git commit -m 'updates from master'

git push -u origin playground-0.1

Can you please let me know whether I am following the correct approach? Thanks a lot!

Upvotes: 1

Views: 839

Answers (1)

VonC
VonC

Reputation: 1324278

Multiple folders are perfectly fine, especially if you need to work at the same time in different branches.

Your merge (git pull) seems correct.
The other approach would be to rebase: see "git merge vs. git rebase", in order to avoid a messy history like:

merges

But that works best if:

  • you didn't already pushed your branch.
  • you rebase on top of origin/sameBranch (ie you rebase your work on top of the same branch which received contribution from other user: that is different from rebasing one's work on top of master).

For different branches (like master and your branch), a merge is preferable, as explained in "Why you shouldn’t use git merge --rebase".

merge

If master introduces some bugs, you know exactly where to look.

Upvotes: 1

Related Questions