Back

Explore Courses Blog Tutorials Interview Questions
+8 votes
2 views
in DevOps and Agile by (19.4k points)
edited by

A new branch from the master is created, we call it a test.

There are several developers who either commit to master or create other branches and later merge into master.

Let's say work on test is taking several days and you want to continuously keep test updated with commits inside the master.

I would do git pull origin master from the test.

Question 1: Is this the right approach? Other developers could have easily worked on same files as I have worked btw.

My work on test is done and I am ready to merge it back to master. Here are the two ways I can think of:

A:

git checkout test

git pull origin master

git push origin test

git checkout master

git pull origin test 

B:

git checkout test

git pull origin master

git checkout master

git merge test

I am not using --rebase because from my understanding, rebase will get the changes from master and stack mine on top of that hence it could overwrite changes other people made.

Question 2: Which one of these two methods is right? What is the difference there?

The goal in all of this is to keep my test branch updated with the things happening in master and later I could merge them back into master hoping to keep the timeline as linear as possible.

1 Answer

+7 votes
by (27.5k points)
edited by

How I would do this

git checkout master

git pull origin master

git merge test

git push origin master

Let us say, I have a local branch from a remote one, I don't feel comfortable with merging other branches than this one with the remote. Also, I would not push my changes, until I'm happy with what I want to push and also I wouldn't push things at all, that are only for me and my local repository. In your description it seems, that test is only for you? So no reason to publish it.

Please go through this tutorial of git which help you to understand git better:

Browse Categories

...