0

How can I sync branches after migration from tfvc so that ahead|behind is 0|0?

The branches are identical in contents but with different history.

We are using Azure DevOps.

git merge syncs up the branches perfectly but also merges in all the commits which is not optimal.

git merge --squash results in nothing to commit and push.

Suggestions?

enter image description here

Martin Nilsson
  • 659
  • 1
  • 8
  • 17

1 Answers1

0

When you are only ahead, syncing a branch is end up to only doing a push.

When you are ahead and behind and you don't mind loosing the commits already pushed in the remote (the behind ones), you need to force push.

I don't know exactly where this option is in Visual Studio (and I'm not in front of my computer ) but from the command line, it should be (if your remote is origin which is most of the times the case) :

git push --force origin dev

Same for your other branches like 'test'.

Philippe
  • 28,207
  • 6
  • 54
  • 78
  • Thank you. I tried that but when everything is up-to-date and there is nothing to push that does not work. Force pushing a small commit also does not reset history. Also tried creating an orphan branch and force pushing that onto its "parent" but no luck. – Martin Nilsson Nov 19 '22 at 15:22
  • @MartinNilsson indeed, if you already synced (with a merge) and are up to date (no ahead, no behind), you have nothing to push. You should reset the current branch to the exact commit you want your remote branch to be on (with a `git reset --hard`. But that's a dangerous command so read the Doc and understand the consequences and select carefully the commit sha1. And stash your changes to have a working directory clean) – Philippe Nov 20 '22 at 14:15