开发者

How to use git feature branches with live updates and merge back to master?

I have a production website where master is checked out and a development webiste where I develop in feature branches.

When a feature is merged into master I do this on the development site:

(currently on the new-feature branch)
$ git commit -m"new feature finished"
$ git push
$ git checkout master
$ git merge new-feature
$ git push

And on the production site:

(currently on master branch)
$git pull

This works for me. But sometimes the client calls and needs a small change on the website quickly. I can do this on production on master and push master and this works fine.

But when I use a feature branch for the small change I get a gap:

(On production on branch master)
$ git branch quick-feature
$ git checkout quick-feature
$ git push origin quick-feature
$ edit files...
$ git add .
$ git commit -m"quick cha开发者_开发技巧nges"
$ git push # until this point the changes are live
$ git checkout master #now the changes are not live anymore GAP
$ git merge quick-feature # now the changes are live again
$ git push

I hope I could make clear the intention of this workflow. Can you recommend something better?


if your quick-feature branch is developed on top of master, you could reset the master branch while still being in the quick-feature branch:

git branch -f master

That way, you avoid the checkout master which removes temporarily from your working tree the quick-feature.

x--x--x  (master)
       \                          => x--x--x--f--f--f--f (master, quick-feature)
        -f--f--f (quick-feature)

Another solution, when you switch back to master, is to ask for a merge

 git checkout --merge master

That allows you to keep quick-feature modification while taking into account the current state of master.


"making the change on production" is just plain wrong, you shouldn't be doing that.

The correct workflow would be: - checkout master on a test/devel site/sandbox/server/whatever - make change, test change - commit change, merge into master, deploy in production

that's what branches are for. You could even make your workflow more automatic by using hooks in git that will automagically deploy in production everything you 'git push' to a specific branch, which may be the master one or another dedicated branch.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜