We work with front-end code, e.g. HTML, CSS, JS etc
We have a preview branch (qa
) on Github that, when pushed to, automatically deploys the code to a preview website for our QA team to test.
We compile / build our code into a dist
directory and this is served on the preview website. Of course, typically the dist
directory would be ignored.
How can we push our development branches and always overwrite our preview branch?
We want to ignore any conflicts and always use the new code we are pushing. The code in the preview branch should never seep back into the development branches. We never ever work on code directly in the preview branch.
We are a small, but geographically distributed team and we work on large front-end projects with several release waves. There is no production as such because our work is supplied to other teams who manage integration with internal CMS systems etc.
The master
branch represents the last release. Typically we will work sequentially, i.e. work on wave1
and release to master
, work on wave2
and release to master
and so on. However sometimes we will need to apply a hotfix to wave1
while we are working on wave2
. The fix in wave1
will need to be temporarily deployed to qa
for testing.
We create feature branches and use Pull Requests to merge them into the current wave branch.
Currently we use this strategy to deploy the current wave to qa
:
git push origin wave2:qa
However this often results in a conflict in the dist
directory, in which case we do this:
git checkout qa
(checkout the qa
branch locally)git pull
(make sure it is up to date)git checkout wave2
(switch back to wave branch)git merge -s ours qa
(merge qa
branch in, using the ours strategy)git checkout qa
(switch back to qa
)git merge wave2
(merge wave2
in)git push
(push to deploy)Now I've noticed that this really screws with our commit history and if we ever need to deploy an older wave to qa
for a hotfix test we can end up with commits (and code a couple of times) in our wave1
branch that should only be in our wave2
branch.
It all feels a bit wrong to me, but I'm not sure what the best solution is here. I think perhaps we're trying to fit a square peg into a round hole using this ours strategy.
Should we be using git push origin wave2:qa --force
instead?
Or perhaps we should have a different remote for the preview branch?
Or maybe the build step should happen on the server so that the dist
directory isn't in the repo?
Happy to work outside our current strategy here as we'd like to move to a more strict git flow
model anyway.
All we really need is a technique that allows us to easily deploy our work to a preview site without encountering conflict issues or cross-contamination of branches / releases.
Use git merge and deal with the merge conflicts or git rebase and rewrite branch history on admit_card. In both cases, git reflog will allow you got go back to an older version. You can even tag the current state of the two branches to make it easier to checkout the original versions at a later time.
Checkout old commits Since this has the potential to overwrite local changes, Git forces you to commit or stash any changes in the working directory that will be lost during the checkout operation. Unlike git reset , git checkout doesn't move any branches around.
Force a Checkout You can pass the -f or --force option with the git checkout command to force Git to switch branches, even if you have un-staged changes (in other words, the index of the working tree differs from HEAD ). Basically, it can be used to throw away local changes.
The “Your local changes to the following files would be overwritten by merge” error occurs when you try to pull a remote repository to your local machine whose contents conflict with the contents of your local version of the repository. To fix this error, either stash your changes away for later or commit your changes.
How can we push our development branches and always overwrite our preview branch?
Should we be using git push origin wave2:qa --force instead?
git push -f ...
The -f (--force) is for force push. It will overwrite the current content of your remote branch. You just have to verify that you have the permissions of doing so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With