Problem: I’m building a pipeline to do stuff in a git repo whenever there’s a push (need to be able to do stuff like git diff
or git merge-base
). The repo takes forever to clone so instead of re-cloning every time at the beginning of the pipeline I want to have the repo persistently cloned and just do a checkout of the respective branch and a pull to start with a current version at each run, and in an idempotent manner.
I got the repo cloned but for the life of me I can’t get the pull working right. Here’s what I’ve tried:
+ git checkout --track master
fatal: missing branch name; try -b
Ok I’ll use -b
.
+ git checkout --track -b origin/master
fatal: a branch named 'origin/master' already exists
I’ll try -B
.
+ git checkout --track -B master
warning: not setting branch 'master' as its own upstream
Maybe that’s the local branch name?
+ git checkout --track -B origin/master
branch 'origin/master' set up to track 'origin/dev'
At least it didn’t fail this time. I suspect I was already on the dev branch or something? But I just wanted to switch to master, obviously I don’t want master to track dev.
I also tried the --set-upstream-to
option which seems to have worked but for some reason my branch diverged even though I haven’t made any local commits–I’ve only done basically git clone
, git checkout
, git pull
.
+ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 13252 different commits each, respectively.
+ git branch --set-upstream-to=origin/master master
branch 'master' set up to track 'origin/master'.
+ git pull --recurse-submodules=no
hint: You have divergent branches and need to specify how to reconcile them.
I’m not good with git other than the basic stuff so if someone could help me figure out what commands I could use to reliably do like a checkout and pull every time the pipeline runs (without creating diverging branches or whatnot), I’d appreciate it.