I am trying to clean up my git repository and
From the command line you can see my environment.
$ git remote
dev
origin
production
staging
$ git branch -r
dev/dev
origin/HEAD -> origin/master
origin/dev
origin/master
production/master
wpengine-findcra/master
$ git branch -vv
dev xxxxxxx <comment>
*master xxxxxxx [origin/master] <comment>
production/staging xxxxxxx [remotes/production/master] <comment>
staging/master xxxxxxx <comment>
I have 4 locations I work out of. Code flows from 1 to 4.
I want to add a new branch specifically for the staging server, and right now I want it to mirror the production (master) branch. But I run into this error and I don't know what to do.
$ git checkout master
$ git branch staging
error: there are still refs under 'refs/heads/staging'
fatal: Failed to lock ref for update: Is a directory
My code is up to date under origin/master and dev/dev.
If you have a branch with a name that contains a slash, git will create (in .git/refs/heads
) a directory named like the name of your branch until the slash. In that directory it will place the refs for the branch itself. So the directory .git/refs/heads/staging/
exists and contains a file "master" due to your branch staging/master
.
When you try to create the branch "staging", git will try to create the file .git/refs/heads/staging
. As this already exists but is a directory, this will fail. Thus you cannot have two branches with these names in your repository.
In more recent versions of git the error message will look like this:
fatal: cannot lock ref 'refs/heads/staging': 'refs/heads/staging/master' exists; cannot create 'refs/heads/staging'
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