g3blv g3blv - 1 month ago 14
Git Question

Can't commit to cloned repository

I'm trying to commit to a local repository that was cloned from GitHub. I get the following error message

fatal: update_ref for ref 'HEAD': cannot lock ref 'HEAD': ref
refs/heads/master is at 2b459....[LOTS OF NUMBERS AND CHARACTERS]...
but expected 000000000000000000000000000


The structure of the .git folder looks as follows:

enter image description here

output from
git status
:

warning: refname 'HEAD' is ambiguous.
warning: refname 'HEAD' is ambiguous.
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

new file: src/actions/types.js
new file: src/components/auth/require_auth.js
new file: src/components/auth/signin.js
new file: src/components/auth/signout.js
new file: src/components/auth/signup.js
new file: src/components/feature.js
new file: src/components/header.js
new file: src/components/welcome.js
new file: src/reducers/auth_reducer.js
new file: style/react-bootstrap-table-all.min.css


out put from
git log --all --oneline --decorate --graph
:

* 1d2e02d (HEAD) First working version
* 2b459d6 (HEAD -> master, origin/master, origin/HEAD) Create .babelrc
* a7b92d5 Merge branch 'master' of github.com:StephenGrider/ReduxSimpleStarter
|\
| * 29ebda4 Merge pull request #8 from megadix/master
| |\
| | * 7a74747 Filter out IntelliJ IDEA project files in .gitignore
| * | decca90 Merge pull request #10 from dkarter/master
| |\ \
| | * | 94692d5 Use destructuring to import Component
| | |/
| * | ff4d48c Merge pull request #24 from tsurupin/add-global-navigator
| |\ \
| | * | d976e01 Add global navigator setting to modify the error, 'navigator is not defined', in testing with react-router link
| * | | b198de2 Merge pull request #29 from hex13/master
| |\ \ \
| | |/ /
| |/| |
| | * | 6246c47 fix typo in README.md
| |/ /
* | | c62b60e moved babel config to webpack
|/ /
* | 2eba18e (tag: 1.1.0) added reactrouter
* | 3ea279e Update package.json
* | 78c0fed tweak mocha test command for windows users
|/
* 3f36bba added test boilerplate and helpers
* 3441a8e Update README.md
* 92d5200 absolute script and css paths
* 81cee14 move history fallback to webpack server config
* 2cd850b using history fallback
* 31208bf Update README.md
* c5ad6ad Update README.md
* 0c7231d Update README.md
* 6aedde6 fix npm start on windows machines
* ec41961 Create README.md
* 7afaf3a added google maps by default
* 0736160 add lodash
* f6a7716 use store with middleware
* 14813f8 middleware setup included by default
* 1b82228 (tag: 1.0.0) Merge branch 'master' of github.com:StephenGrider/ReduxSimpleStarter
|\
| * fe018bf add default reducer
* | 3aa34af added css
|/
* e4c4496 state-1 -> stage-1
* 4709b14 added babel preset
* 05173d9 used class container as root node
* 148f186 added bootstrap
* 9128a89 code cleanup
* dd358d4 reorder imports
* 3f0e441 update default text
* 9eff420 action and reducer setup
* 246b131 added redux
* f71dda3 add react redux and redux
* 544ddfd update repository field
* dedb285 update package.json
* dff784d initial commit


output from
git branch --all


HEAD
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master


I was able to commit after running
git branch -D HEAD


The outputs now look like:

git status


On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working directory clean


git log --all --oneline --decorate --graph


* 8a21399 (HEAD -> master) First working version (from git-gui)
* 2b459d6 (origin/master, origin/HEAD) Create .babelrc
* a7b92d5 Merge branch 'master' of github.com:StephenGrider/ReduxSimpleStarter
|\
| * 29ebda4 Merge pull request #8 from megadix/master
| |\
| | * 7a74747 Filter out IntelliJ IDEA project files in .gitignore
| * | decca90 Merge pull request #10 from dkarter/master
| |\ \
| | * | 94692d5 Use destructuring to import Component
| | |/
| * | ff4d48c Merge pull request #24 from tsurupin/add-global-navigator
| |\ \
| | * | d976e01 Add global navigator setting to modify the error, 'navigator is not defined', in testing with react-router link
| * | | b198de2 Merge pull request #29 from hex13/master
| |\ \ \
| | |/ /
| |/| |
| | * | 6246c47 fix typo in README.md
| |/ /
* | | c62b60e moved babel config to webpack
|/ /
* | 2eba18e (tag: 1.1.0) added reactrouter
* | 3ea279e Update package.json
* | 78c0fed tweak mocha test command for windows users
|/
* 3f36bba added test boilerplate and helpers
* 3441a8e Update README.md
* 92d5200 absolute script and css paths
* 81cee14 move history fallback to webpack server config
* 2cd850b using history fallback
* 31208bf Update README.md
* c5ad6ad Update README.md
* 0c7231d Update README.md
* 6aedde6 fix npm start on windows machines
* ec41961 Create README.md
* 7afaf3a added google maps by default
* 0736160 add lodash
* f6a7716 use store with middleware
* 14813f8 middleware setup included by default
* 1b82228 (tag: 1.0.0) Merge branch 'master' of github.com:StephenGrider/ReduxSimpleStarter
|\
| * fe018bf add default reducer
* | 3aa34af added css
|/
* e4c4496 state-1 -> stage-1
* 4709b14 added babel preset
* 05173d9 used class container as root node
* 148f186 added bootstrap
* 9128a89 code cleanup
* dd358d4 reorder imports
* 3f0e441 update default text
* 9eff420 action and reducer setup
* 246b131 added redux
* f71dda3 add react redux and redux
* 544ddfd update repository field
* dedb285 update package.json
* dff784d initial commit


git branch --all


* master
remotes/origin/HEAD -> origin/master
remotes/origin/master


git version 2.7.4 and I'm running Ubuntu 16.04

How do I fix this issue?

Answer

The error is because the repository has a branch called HEAD. Since HEAD keeps track of the current working commit, Git becomes confused between the branch named HEAD and git's internal pointer to the current working commit (hence warning: refname 'HEAD' is ambiguous messages.)

You could try git branch -D HEAD (the normal way to remove a branch), but I am not sure whether or not this would confuse git even more.