Bash Function that Continues After Git Merge, Even With Conflicts - Stack Overflow

createBranch() {git pullgit checkout -b $1git push --set-upstream origin $1}createBranchOffFeature()

createBranch() {
  git pull
  git checkout -b $1
  git push --set-upstream origin $1
}
createBranchOffFeature() {
  git checkout master
  git pull
  git checkout feature-branch
  git pull
  git merge master
  # there are conflicts and I need to do a merge commit and push before continuing
  git push
  createBranch "$1"
}

I'm working on a project, and several of us are merging to master every day. My feature branch was branched off master. When I work a new story in the feature, I need to create a new branch off feature-branch, but I need to make sure that master has been merged into feature-branch before I make the new branch.

I almost always have merge conflicts in my package.json, because I have updated a package for this feature, and my coworkers have updated the same package for continued development on that package. We need to deploy my changes to that package at the same time as this feature deploys, but not before, so I can't just merge the package on that end (yet). There is another package under development as well, and I do need the updates they are making to that package. So if the merge conflict looks like:

<<<<< HEAD
7 "@proprietary/package": "/@example/package-110-feature.tgz",
8 "@proprietary/package2": "/@example/package2-1.0.0.tgz",
=====
7 "@proprietary/package": "/@example/package-113.tgz",
8 "@proprietary/package2": "/@example/package2-1.0.2.tgz",
>>>>> master

Then I keep my package and their package2, and delete the other 5 lines.

Sometimes there are other conflicts as well, so generally I am going to have to fix merge conflicts manually, and then I perform the git commit, and at that point, I want my function to pick back up and finish making the branches.

Is this possible? If so, what do I need to do on the commented line of the function in order to do it?

Right now I'm using read on that line to wait for any input.

It works fine, but because I've been testing iterative versions of this function, there are no longer any merge conflicts, so it's just pausing after the merge says "Already up-to-date". I press Enter and it continues as I expect.

Will this work if I type git commit there instead?

Could I do something like:

read
git commit -am "merging master into feature"

But what if there wasn't a merge conflict, because I finished a small story before anyone else merged to master? Can I conditionally do the git commit?

createBranch() {
  git pull
  git checkout -b $1
  git push --set-upstream origin $1
}
createBranchOffFeature() {
  git checkout master
  git pull
  git checkout feature-branch
  git pull
  git merge master
  # there are conflicts and I need to do a merge commit and push before continuing
  git push
  createBranch "$1"
}

I'm working on a project, and several of us are merging to master every day. My feature branch was branched off master. When I work a new story in the feature, I need to create a new branch off feature-branch, but I need to make sure that master has been merged into feature-branch before I make the new branch.

I almost always have merge conflicts in my package.json, because I have updated a package for this feature, and my coworkers have updated the same package for continued development on that package. We need to deploy my changes to that package at the same time as this feature deploys, but not before, so I can't just merge the package on that end (yet). There is another package under development as well, and I do need the updates they are making to that package. So if the merge conflict looks like:

<<<<< HEAD
7 "@proprietary/package": "https://gitlab.proprietary/@example/package-110-feature.tgz",
8 "@proprietary/package2": "https://gitlab.proprietary/@example/package2-1.0.0.tgz",
=====
7 "@proprietary/package": "https://gitlab.proprietary/@example/package-113.tgz",
8 "@proprietary/package2": "https://gitlab.proprietary/@example/package2-1.0.2.tgz",
>>>>> master

Then I keep my package and their package2, and delete the other 5 lines.

Sometimes there are other conflicts as well, so generally I am going to have to fix merge conflicts manually, and then I perform the git commit, and at that point, I want my function to pick back up and finish making the branches.

Is this possible? If so, what do I need to do on the commented line of the function in order to do it?

Right now I'm using read on that line to wait for any input.

It works fine, but because I've been testing iterative versions of this function, there are no longer any merge conflicts, so it's just pausing after the merge says "Already up-to-date". I press Enter and it continues as I expect.

Will this work if I type git commit there instead?

Could I do something like:

read
git commit -am "merging master into feature"

But what if there wasn't a merge conflict, because I finished a small story before anyone else merged to master? Can I conditionally do the git commit?

Share Improve this question asked Feb 12 at 20:49 Ella MolnarElla Molnar 11 bronze badge 9
  • 2 If you git merge --no-commit to start with, then whether there is a conflict or not, git commit will complete the merge. – matt Commented Feb 12 at 20:56
  • Can you do merging with if git merge master and take actions depending the result of the merge ? – Philippe Commented Feb 12 at 21:35
  • What would you expect? You continue execution after git merge master unconditionally. To make it conditional, you would need to capture stdout (stderr?) and analyzed that string. – Sergey A Kryukov Commented Feb 12 at 23:03
  • @matt, I need to fix the conflicts, and there nearly always are conflicts. – Ella Molnar Commented Feb 13 at 20:56
  • @Philippe, I always need to merge master. How do I get the bash script to see the result of the merge? – Ella Molnar Commented Feb 13 at 20:57
 |  Show 4 more comments

1 Answer 1

Reset to default 0

You can do something like :

...
  git pull
  if ! git merge master; then
     read -p "Try to resolve conflicts in another bash session, and type Enter once done"
  fi
  git push
...

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745202736a4616423.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信