Search code examples
gitproduction-environment

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 changes"
$ 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?


Solution

  • 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.