Help with Git incantations

For those of you following my journey with wry amusement, I’m now pretty much setup according to the diagram in my beginner’s tutorial on Version Control:

I have my Production clone WGACA_UK_PROD running on Anvil while I continue to tinker on the WGACA_DEV-TEST version, also in Anvil:

I have a local clone on my workstation that pushes and pulls nicely with Anvil_WGACA_UK_DEV_TEST and GitHub_WGACA_DEV_TEST and what I want to do, ideally with one or two Git incantations, is also push to the Anvil Production Clone:

I’ve added the Anvil Production Clone using git remote add Anvil_WGACA_UK_PROD ssh://<the id of the production clone given when I go to the Git Clone menu in Anvil>.git

But when I try to push to this new remote I get:

fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream WGACA_UK_PROD master

So I dutifully enter the --set-upstream incantation and get:

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'ssh://xxxxxxxx.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

So I try git pull WGACA_UK_PROD master as suggested but get:

From ssh://anvil.works:2222/xxxxxx
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

Can anyone put me out of my misery please and tell me how to push changes to my Anvil Production Clone?

The problem here is that your two repositories at Anvil are entirely separate and don’t share the same history of commits.

You’ll need to force push to your dev-test clone from your production clone so that the history of the production app overwrites everything on the dev-test app.

After that, you’ll be dealing with anvil.yaml hell…

1 Like

Thanks Owen - I note your ominous warning about Anvil yaml hell but could you clarify what you mean by “force push to your dev-test clone from your production clone?” Cheers!

A force push to a remote says “I don’t care what history exists in the remote, just push what I’m telling you and overwrite everything at the other end.”

It’s a destructive operation. You will lose everything in the target anvil app if you force push to it.

However, for a workflow with multiple anvil apps as remotes, you have to ensure they have shared history, so you need to force push from one of them to all the others (and that really ought to be from production to any dev or testing clones).

So, assuming you’ve created a fresh anvil clone of your production app, called it ‘dev-app’, created a local git repository by git cloning production, added dev-app as another remote and checked out a local branch called master from production/master, you would then force push that branch to dev-app with:

git push -f master dev-app:master

That command can be read as “Take my local master branch and force the master branch at dev-app to become identical regardless of what happens to be there at the moment.”

1 Like

Much appreciated… I’ll double check my setup and I’ve thoroughly understood your reply and give it try!