Domanda

I have created an empty Git repository in Atlassian Stash and cloned it.

$ git clone http://me@myrepo/my/repo.git
...
warning: You appear to have cloned an empty repository.

Then I've created some files, added them via git add and wanted to commit via git commit. I get the following error:

ERROR: Unable to determine active branch in current context !
ERROR: GITLib::Branch::get_current died at line 41

When I do git rev-parse HEAD I get:

$ git rev-parse HEAD
HEAD
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.

When I issue git branch -a to see if there are any remote branches, the output is empty.

Let's create a branch locally:

$ git checkout -b "foo"
Switched to a new branch 'foo'

$ git commit -m "test"
ERROR: Unable to determine active branch in current context !
ERROR: GITLib::Branch::get_current died at line 41

How do I get my repo in a workable state?

I tried issuing git commit --allow-empty, git init but it didn't change anything.

Edit:

When I just create an empty repo locally with git init, then git add and try to git commit similar happens:

ERROR: GIT::Command::git_or_die died at line 164

Edit 2:

It seems an internal issue due to a hook in my company. I'll follow up with details if this gets resolved.

Using Git Bash 1.8.5.2 @ Win7.

È stato utile?

Soluzione 3

The issue was caused indeed by global hooks installed by the platform team in my company. The message looks like it was some Git internals and that's why it mislead me.

What I've done was to remove the hooks locally from .git/hooks and deactivate the hooks copying on the repo creation:

Run git config --system -e to open the editor for system config file (C:\Program Files (x86)\Git\etc\gitconfig in my case) and removed the following lines:

[init]
    templatedir = D:/tools/Git/hooks/templates

Altri suggerimenti

Rather than cloning the empty repository from Stash, try creating a new repository locally (in a new directory) with:

git init .

Add your files and make your first commit. The freshly init'd repository should have a proper HEAD and master branch:

git add file1.txt
git add file2.txt
git commit

Then, add your empty Stash repo as a remote and push master there:

git remote add origin http://me@myrepo/my/repo.git
git push -u origin master

Actually you guessed it right, this is something totally into your (and actually our, as I'm in charge of them) company hooks.

The error:

ERROR: Unable to determine active branch in current context !
ERROR: GITLib::Branch::get_current died at line 41

occurs when we try to find the name of the current branch. Currently we are using "git branch --list" to find it, but in case of empty repo this returns an empty result.

The solution would need to go to something else, probably "get symbolic-ref" as suggested here: https://stackoverflow.com/a/2111099 (issue is we have to support clients still in Git 1.7.9)

Phil.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top