1

I have a branch which is used for deploying the latest changes into a certain environment. Let's call it test. The test branch is used to deploy whatever it has into the test environment.

Now I work on a feature in a feature branch called feature1. I'm done with my changes and I have merged everything in my feature branch into master.

The contents in the test branch which is already deployed into test is successfully tested and moved to the uat environment. Now I want to bring everything in master into the test branch so that my changes are deployed to the test environment. I have a couple of questions though! I'm a bit hesitant to do a merge as I'm afraid that it might get into conflicts and I have to resolve them manually.

How can I replace the test branch both locally and on remote to use the latest contents in master? I have a commit id for my master. I want my test branch to update its contents based on this commit id.

Is this a good approach? Any suggestions?

joesan
  • 13,963
  • 27
  • 95
  • 232
  • I see nothing wrong with merging `master` into your testing branch. You may have conflicts but there is no way around avoiding these. How are you hosting your Git repo (e.g. GitHub, BitBucket, etc.) ? – Tim Biegeleisen Jul 06 '15 at 08:36
  • I use GitLab repository – joesan Jul 06 '15 at 08:37
  • I come from SVN and all I could think of is just a new branch with a new version number. But in Git, the branch is more like a bucket which gets the latest changes and once these changes are tested, it gets the next one – joesan Jul 06 '15 at 08:38
  • 1
    Yes, learn your `git` and how it does things. SVN is just a linear subset of the way git handles changes. – ikrabbe Jul 06 '15 at 08:41
  • I know Git to some extent but I'm new to GitLab and it seems there are different ways to use Git workflows! – joesan Jul 06 '15 at 08:48
  • yes, there are different workflows; but `GitLab` won't force you to use a given workflow, esp. it won't hinder you to use basic git functionality like `pull`, `cherry-pick` and `merge`. – umläute Jul 06 '15 at 08:53

4 Answers4

1

yes, just use merging:

$ git checkout master
$ git merge <commit>
$ git push

if you want to merge master into test, run the git merge command within the test branch:

$ git checkout test
$ git merge <commit>
$ git push

basically, git merge will always merge into the current branch.

umläute
  • 28,885
  • 9
  • 68
  • 122
  • the git merge would apply all the changes prior to that commitId? I would assume so! or? – joesan Jul 06 '15 at 08:40
  • I want to have it the other way! I want to merge everything that is in master into the test branch! – joesan Jul 06 '15 at 08:44
  • well, then run the `merge` command within the `test` branch. `git` has no special branch names (that is: it's the humans that assign different meanings to `master` and `test`) – umläute Jul 06 '15 at 08:51
  • and yes, `git merge` will get the entire history up to ``; if you only want to include a *single* commit, use `git cherry-pick` – umläute Jul 06 '15 at 08:54
  • git merge --abort would abort the merge if there are conflicts or? – joesan Jul 06 '15 at 08:57
  • it will abort execution and give you the opportunity to resolve the conflicts. on abortion, `git merge` will return an exit code `!= 0`, so you can automatically decide what to do next (e.g. abort the entire merge and send an email to your employer) – umläute Jul 06 '15 at 09:04
1

Don't be afraid! If you run into too many conflicts with merge you can always --abort the merge.

You can cherry-pick a single commit from master into your test branch if that is what you want. You can --abort this too, if this leads into conflicts and you don't like to remove them.

Finally you can simply checkout master -- . to overwrite any tracked files form master in your test branch and look at the differences. But that would be a quite rude way and it creates a new commit that does not relate to the commits in feature1 and master.

AND Read you manual, please! git help merge, git help cherry-pick, git help reset, git help checkout ... and so on. (If you like it, try git help --web git.)

ikrabbe
  • 1,909
  • 12
  • 25
1

I suggest creating another branch consisting of the master & the test branch in question.

You might find this helpful: How do I check out a remote Git branch?

Community
  • 1
  • 1
0

I have the following in mind:

git checkout master
git pull
git checkout featureBranch
git pull
git merge master
git push origin featureBranch
joesan
  • 13,963
  • 27
  • 95
  • 232
  • git merge master --abort would abort the merge from master into the featureBranch if there are conflicts – joesan Jul 06 '15 at 08:58