887

Using git 1.6.4.2, when I tried a git pull I get this error:

error: unable to resolve reference refs/remotes/origin/LT558-optimize-sql: No such file or directory
From git+ssh://remoteserver/~/misk5
 ! [new branch]      LT558-optimize-sql -> origin/LT558-optimize-sql  (unable to update local ref)
error: unable to resolve reference refs/remotes/origin/split-css: No such file or directory
 ! [new branch]      split-css  -> origin/split-css  (unable to update local ref)

I've tried git remote prune origin, but it didn't help.

Braiam
  • 1
  • 11
  • 47
  • 78
Gabrielle
  • 8,989
  • 4
  • 17
  • 6

39 Answers39

1369

Try cleaning-up your local repository with:

$ git gc --prune=now
$ git remote prune origin

man git-gc(1):

git-gc - Cleanup unnecessary files and optimize the local repository

git gc [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune]

       Runs a number of housekeeping tasks within the current repository, such as compressing file revisions
       (to reduce disk space and increase performance) and removing unreachable objects which may have been
       created from prior invocations of git add.

       Users are encouraged to run this task on a regular basis within each repository to maintain good disk
       space utilization and good operating performance.

man git-remote(1):

git-remote - manage set of tracked repositories

git remote prune [-n | --dry-run] <name>

           Deletes all stale remote-tracking branches under <name>. These stale branches have already been
           removed from the remote repository referenced by <name>, but are still locally available in
           "remotes/<name>".            
hexacyanide
  • 88,222
  • 31
  • 159
  • 162
Vojtech Vitek - golang.cz
  • 25,275
  • 4
  • 34
  • 40
  • 169
    Why does this work? What is the problem that it fixes? – Ikke Feb 14 '17 at 14:22
  • 7
    The second command worked for me. Apparently I had a broken reference to a remote branch that was just created. Not sure how it happened, but glad it was a simple fix. Thanks Vitek! – JGTaylor Jul 20 '17 at 16:56
  • It worked for me. But after running these codes I had to run "pull" request again. Thanks for a help – David Apr 28 '18 at 05:47
  • 2
    This worked perfectly! I'd also love an explanation of what this does and why this worked. Thanks! – ArielSD Sep 18 '18 at 18:31
  • 7
    Will the ``git remote prune origin`` command run on my local working copy or on the remote repository? – user1438038 Dec 17 '18 at 11:48
  • 4
    @user1438038 It should not remove any branches and only update remote ref's in your local working copy. More info here: https://stackoverflow.com/questions/20106712/what-are-the-differences-between-git-remote-prune-git-prune-git-fetch-prune – Zengineer Mar 01 '19 at 22:55
  • @vojtech vitek how do you fix this on the server? – Nick Turner Jun 18 '20 at 13:58
  • `git gc --prune=now` outputs errors: `error: bad ref for .git/logs/refs/remotes/origin/feature/gal-42` and then `fatal: bad object refs/remotes/origin/feature/GAL-42` and then `fatal: failed to run repack`. `git fetch` still doesn't work afterwards. – OzrenTkalcecKrznaric Jan 08 '21 at 16:03
  • Weirdly on the same branch i had to run `git remote prune origin` twice before the problem was fixed. – bytedev Jun 09 '21 at 07:53
  • `git remote prune origin` fixed my `error: cannot lock ref` error which I saw when I ran `git pull`. Now, `git pull` works properly again. I first saw that command [in this article here](https://linuxpip.org/git-error-cannot-lock-ref/), then I saw your answer above. – Gabriel Staples Mar 22 '22 at 17:32
  • If suddenly someone didn’t like the solution and the following error appeared: `fatal: bad object refs/tags/%tag-name%, fatal: failed to run repack`, then it helped me to go to the `.git/refs/tags/` folder and delete file `%tag-name%`. It was empty. After that `git pull` worked as it should – Alexander Nov 29 '22 at 07:49
809

Happened to me as well. In my case, the bad ref was master, and I did the following:

rm .git/refs/remotes/origin/master
git fetch

This made git restore the ref file. After that everything worked as expected again.

William Jockusch
  • 26,513
  • 49
  • 182
  • 323
Michel Krämer
  • 14,197
  • 5
  • 32
  • 32
  • 2
    I did the same thing, and it solved my problem. When I opened the file in Notepad++, it was clearly corrupted. – theMayer Oct 26 '13 at 14:52
  • 104
    make sure you choose the file that is giving you problems instead of master – bia.migueis Jan 20 '14 at 19:10
  • 9
    @bia.migueis: it's not gonna damage anythin if you accidentally remove master as well though - it'll just get updated next fetch too. – naught101 Jul 07 '14 at 00:10
  • Did this. Now getting another error, "error: unable to resolve reference ORIG_HEAD: No error". Edit: Fixed the secondary error with "rm .git/ORIG_HEAD" – pk1557 May 11 '15 at 20:39
  • Thanks for this solution. In my case the file for the branch was empty. How did this happen is a mystery because yesterday I was still committing changes for that branch from the same folder. After removing it and do a fetch the problem was fixed. – racs Jun 25 '15 at 21:16
  • Worked for me but my problem was a tag so as @bia.migueis mentioned, I needed to delete the file under `.git/refs/tags/` – Tom Saleeba Aug 11 '15 at 03:30
  • Any idea _why_ this happens? I'm just pushing, pulling, fetching, rebasing, merging as normal and then I come across this error. Is it an issue found in certain versions of Git? – crmpicco Aug 11 '15 at 09:33
  • @crmpicco AFAIR mine was corrupted due to a computer crash – Michel Krämer Aug 12 '15 at 05:02
  • @MichelKrämer Interesting. As in did you have a WSOD in Windows or something similar? When this happened the first time to me I believed it was because I didn't shut down my Virtual Machine properly, however it still seems to happen even though now I do. – crmpicco Aug 12 '15 at 08:20
  • @crmpicco I don't think it was a BSOD (didn't happen to me for quite some time). Must have been a power outage or something. Can't really remember. The problem has never occurred again by the way. – Michel Krämer Aug 14 '15 at 16:42
  • After doing: rm .git/refs/remotes/origin/master, git fetch will remove the ref error.. but when i do the git pull again the same error comes.. so i did a git gc --prune=now.. and it worked... – abyin007 Sep 14 '15 at 07:07
  • Had the exact same issue; the file was filled with NULL characters :-/ – NKCSS Oct 16 '15 at 05:58
  • 2
    If it is a submodule, it might be slightly tricky to find the ref. First check if `.git` is a folder by doing `ls -la` if not, see the contents of the file `.git` file to find the actual .git folder in which the refs are. `.git` file contents in my case: `gitdir: ../.git/modules/my-submodule-name` – CCoder Nov 30 '16 at 07:23
  • I had this problem with a few branches, and I had them all pushed, so I just deleted whole "origin" folder – George Lanetz Mar 12 '18 at 15:28
  • 2
    Twice now in the past year I've come back to have to fix this and again, this is the only fix that actually works. – Ted Apr 16 '20 at 17:04
  • 1
    None of the other solutions worked for me until I did that (prune did nothing). I run `rm .git/refs/remotes/origin/MY_BROKEN_BRANCH_NAME` – MarcinWolny Mar 23 '21 at 09:28
  • The solution provided by Vojtech Vitek didn't work for me but this solution worked. – mayankkaizen Dec 30 '22 at 06:46
180

This did the job for me:

git gc --prune=now
Cosmin
  • 21,216
  • 5
  • 45
  • 60
Bernd
  • 1,829
  • 1
  • 11
  • 5
  • git gc docs are [here](https://www.git-scm.com/docs/git-gc/1.6.5#git-gc---pruneltdategt) – BigRon Sep 21 '18 at 19:41
  • 1
    Worked for me too. Didn't need to run `git remote prune origin` – Airwavezx Jan 17 '19 at 08:33
  • Had to move the bad references that the terminal was mentioning out of the .git folder before that command would run, but after that this command ran, and I was able to continue merrily on my coding journey! – TripWire Nov 12 '20 at 01:37
  • Running this command accused the problem in my case: ```fatal: bad object refs/remotes/origin/HEAD fatal: failed to run repack``` so I ran `rm .git/refs/remotes/origin/HEAD` and later `git gc --prune=now` and now the repo is clean as new. – Josep Bigorra Mar 01 '21 at 12:57
112

For me, it worked to remove the files that are throwing errors from the folder .git/refs/remotes/origin/.

David Ferenczy Rogožan
  • 23,966
  • 9
  • 79
  • 68
Brian van Rooijen
  • 1,906
  • 1
  • 14
  • 10
  • that did it! But just out of curiosity do you know why this error came? (everything was working fine and then suddenly one day this error popped). And also do you know how deleting the file solved it? – Shreyans Apr 02 '16 at 11:06
  • Good to hear this also fixed it for you. To be honest i have no idea what caused the error to appear. My thought was that one of the files in the folder had gone out of sync. Since none of the other fixes i found worked for me i used this as a last resort. – Brian van Rooijen Apr 04 '16 at 09:31
  • Worked great! Notice you have to delete all files that causing the problem (based on the error report you are getting), as if you only delete one and try pulling it will come back. – Rayee Roded Oct 20 '17 at 22:42
  • 3
    One of the possible causes may be the system crash as I described in [my answer](https://stackoverflow.com/a/50467268/971141). Many Git GUI applications periodically run Git on your repo (to refresh the status) and if your system crashes during Git is manipulating with the references, they may end up rewritten with `NULL`s. – David Ferenczy Rogožan Jul 24 '18 at 17:00
  • 1
    My system crashed just as a sync operation was about to complete and this helped. – Padmika Nov 27 '20 at 02:37
  • 1
    I forced shutdown my laptop without closing all apps. It caused the issue. Deleting the C:\git\repo1\.git\logs\refs\remotes\origin helped – Chinmoy Feb 28 '23 at 07:11
102

I just would like to add one of the possible causes of a broken Git reference.

Possible root cause

On my system (Windows 7 64-bit), when a BSOD happens, some of the stored reference files (most likely currently opened/being written into when the BSOD happened) are overwritten with NULL characters (ASCII 0).

As others mentioned, to fix it, it's enough to just delete those invalid reference files and re-fetch or re-pull the repository.

Example

Error message:

cannot lock ref 'refs/remotes/origin/some/branch': unable to resolve reference 'refs/remotes/origin/some/branch': reference broken

Solution:

Delete the reference refs/remotes/origin/some/branch which is stored in the file %repo_root%/.git/refs/remotes/origin/some/branch.

David Ferenczy Rogožan
  • 23,966
  • 9
  • 79
  • 68
  • 5
    Same scenario on Windows 10 64bit - working in a git repo when BSOD happens. `error: cannot lock ref 'refs/remotes/origin/master': unable to resolve reference 'refs/remotes/origin/master': reference broken`. Trying to `git pull` after deleting the first file returned `fatal: update_ref failed for ref 'HEAD': cannot lock ref 'HEAD': unable to resolve reference 'refs/heads/master': reference broken`. After deleting the second file `git pull origin master` was successful. – c.j.mcdonn Sep 19 '18 at 18:50
  • Simplest solution so far – George Sep 16 '21 at 14:30
  • 1
    Had a BSOD. This solved my problem. – ThomasMX Nov 16 '21 at 14:37
  • this is what worked for me after all – MindRoasterMir Mar 18 '22 at 13:14
87

Go to under flutter folder and then,

Try it:

git gc --prune=now

git remote prune origin

git pull
Samet ÖZTOPRAK
  • 3,112
  • 3
  • 32
  • 33
annelorayne
  • 1,404
  • 13
  • 10
  • 40
    While this might answer the authors' question, it lacks some explaining words and/or links to documentation. Raw code snippets are not very helpful without some phrases around them. You may also find [how to write a good answer](https://stackoverflow.com/help/how-to-answer) very helpful. Please edit your answer. – Roy Scheffers Nov 23 '18 at 21:57
  • Exactly the point. It's not enough to right the code and that's it. I hope there's an explanation – Musikero31 Jun 15 '19 at 04:57
  • 1
    git gc --prune=now updates local repository while deleting unnecessary files. It works for me fine. – Vasyl Gutnyk Apr 19 '20 at 18:39
86

Explanation: It appears your remote repo (in GitHub / BitBucket) branches were removed ,though your local references were not updated and pointing to non existent references.

In order to solve this issue:

git fetch --prune
git fetch --all
git pull

For extra reading - Reference from Git documentation :

git-fetch - Download objects and refs from another repository

--all Fetch all remotes.

--prune After fetching, remove any remote tracking branches which no longer exist on the remote.

Harsh Patel
  • 6,334
  • 10
  • 40
  • 73
avivamg
  • 12,197
  • 3
  • 67
  • 61
53

Execute the following commands:

rm .git/refs/remotes/origin/master

git fetch

git branch --set-upstream-to=origin/master

Just in case, if you need to know what is .git/refs/remotes/origin/master, you would read the Remotes section in Git References.

Matias Sebastiao
  • 2,000
  • 1
  • 15
  • 14
51

git fetch --prune fixed this error for me:

[marc.zych@marc-desktop] - [~/code/driving] - [Wed May 10, 02:58:25]
[I]> git fetch
error: cannot lock ref 'refs/remotes/origin/user/janek/integration/20170505': 'refs/remotes/origin/user/janek/integration' exists; cannot create 'refs/remotes/origin/user/janek/integration/20170505'
From github.com:zooxco/driving
 ! [new branch]            user/janek/integration/20170505 -> origin/user/janek/integration/20170505  (unable to update local ref)
From github.com:zooxco/driving
[marc.zych@marc-desktop] - [~/code/driving] - [Wed May 10, 02:58:30]
[I]> git fetch --prune
 - [deleted]               (none)     -> origin/user/janek/integration

This assumes that the offending branch was deleted on the remote, though.

You can also add this to ~/.gitconfig to automatically prune when running git fetch:

[fetch]
    prune = true
marczych
  • 967
  • 7
  • 15
  • Your example seems incomplete: it doesn't show the `--prune` that I can see. Also proTip: remove useless password prompts after pasting examples. – MarkHu Aug 04 '17 at 22:28
  • You're absolutely right - I left off the output from the fetch command but I just put it into the example. Thanks for the tip on removing the password prompt too! – marczych Aug 05 '17 at 18:17
49

In my case, the problem was solved after I've deleted all the remove reference files under the directory .git.

If you look at the message, it would tell you which files you need to delete (specifically).

The files to delete sit under .git/refs/remotes.

I've just deleted all the files there, and ran gc prune

git gc --prune=now

After that, everything works just fine.

David Ferenczy Rogožan
  • 23,966
  • 9
  • 79
  • 68
Uri Shtand
  • 1,717
  • 11
  • 14
46

I had this same issue and solved it by going to the file it was erroring on:

\repo\.git\refs\remotes\origin\master

This file was full of nulls, I replaced it with the latest ref from github.

Noel Tock
  • 609
  • 6
  • 13
  • 3
    Had the same issue, but the file `.git/refs/remotes/origin/master` was just empty. Solved the problem by removing it. – zinovyev Dec 30 '16 at 16:05
28

If this error “unable to update local ref” is reoccurring, even after applying either the answer by Vojtech Vitek or Michel Krämer you may you may have a bad ref on your local AND master repository.

In this case you should apply both fix's without pulling or pushing in between ...

rm .git/refs/remotes/origin/master
git fetch
git gc --prune=now
git remote prune origin

A permanent resolution for me was only achieved after applying both fix's before push/pull.

Inyoka
  • 1,287
  • 16
  • 24
  • 3
    Thanks for this. note that I replaced 'master' with the branch which was failing eg - rm .git/refs/remotes/origin/develop – Damien Sawyer Jan 02 '20 at 21:46
18

For me, I solved it this way:

rm .git/refs/remotes/origin/master
git fetch

After that I get this message from github.

There is no tracking information for the current branch

So next I did to fix this was:

git branch --set-upstream-to=origin/master master
git pull
Deviance
  • 465
  • 4
  • 9
15

To Answer this in very short, this issue comes when your local has some information about the remote and someone changes something which makes remote and your changes unsync.

I was getting this issue because someone has deleted remote branch and again created with the same name.

For dealing with such issues, do a pull or fetch from remote.

git remote prune origin

or if you are using any GUI, do a fetch from remote.

enter image description here

Abhijeet Kamble
  • 3,131
  • 2
  • 30
  • 36
8

Try this:

git pull origin Branch_Name

Branch_Name, the branch which you are currently on.

If you do only a git pull, it pulls all other created branch name as well.

So is the reason you are getting this:

! [new branch]      split-css  -> origin/split-css  (unable to update local ref)
Shiva127
  • 2,413
  • 1
  • 23
  • 27
user3832506
  • 93
  • 2
  • 4
7

Error: cannot lock ref" simply means information in /refs are corrupted and Git cannot continue to create index.lock file.

Quick fix : Remove and re-add remote.

1- Copy the SSH git URL of your existing remote. You can print it to the terminal using this command:

git remote -v

2- Remove the remote from your local git repo:

git remote rm origin

3- Add the remote back to your local repo:

git remote add origin git@server-address.org:your-username/repo-name.git

4- Prune remote origin Users across online forums have reported that the command below worked for them:

git remote prune origin

5- Clean up and optimize local repository git gc --prune=now

You can find more info on this article: https://linuxpip.org/git-error-cannot-lock-ref/

Liran H
  • 9,143
  • 7
  • 39
  • 52
Daher
  • 1,001
  • 10
  • 10
  • 1
    This is the only answer that worked for me. Did a "git fetch" afterwards, then when I tried the "git pull", it failed due to no tracking info. Had to first execute "git branch --set-upstream-to origin/master master", the finally redo the "git pull". – Joseph Waweru Jun 23 '23 at 03:23
6
$ rm .git/refs/remotes/origin/master

$ git fetch

From bitbucket.org:xx/mkyong-tutorials

df0eee8..3f7af90  master     -> origin/master

$ git pull

Already up to date.

Kuro Neko
  • 795
  • 12
  • 19
Ahmad Reza Azimi
  • 534
  • 5
  • 16
5

I was able to work with

git remote update --prune
MCSH
  • 405
  • 4
  • 16
user1238353
  • 179
  • 2
  • 15
4

delete file for particular branch manually from your project

.git/refs/remotes/origin/master
 git gc --prune=now
 git pull
sweetnandha cse
  • 705
  • 7
  • 16
3

Tried these but didn't work for me:

$ git gc --prune=now
$ git remote prune origin
$ git fetch --prune

I had to get this fixed by deleting the local folder and cloning again.

Nisal Gunawardana
  • 1,345
  • 16
  • 20
2

For me, I had a local branch named feature/phase2 and the remote branch was named feature/phase2/data-model. The naming conflict was the cause of the problem, so I deleted my local branch (you could rename it if it had anything you needed to keep)

Nathan Wallace
  • 2,154
  • 4
  • 23
  • 28
  • Same issue here - ours also was a Mac/PC case-naming issue, which made it tricky to spot (one name was capitalized, the other not - and it worked on the PC, but not Mac) – rocksteady Jun 10 '19 at 14:55
2

If git gc --prune=now dosen't help you. (bad luck like me)

What I did is remove the project in local, and re clone the whole project again.

Eric Chen
  • 3,708
  • 2
  • 18
  • 15
2

I'm using Tower and for some reason my folder name was .git/refs/remotes/origin/Github. Changing it to lowercase .git/refs/remotes/origin/github solved the issue.

split19
  • 597
  • 7
  • 18
2

When it is caused by Google Drive desktop.ini files

Google Drive client for Windows creates desktop.ini files in each folder. If your git repository is in a directory that is being synced with Google Drive, then the desktop.ini files will cause the git repository to fail with something like:

cannot lock ref 'refs/remotes/origin/desktop.ini': unable to resolve reference 'refs/remotes/origin/desktop.ini': reference broken

To solve this error you might want to delete the desktop.ini files in your git repository.

If you have WSL setup, then you can use the following command to delete the desktop.ini files:

Note: ⚠️ This command will delete all desktop.ini files in all .git directories in your <project_directory>.

find <project_directory> -type d -name .git -print0 | xargs -0 -I {} find {} -type f -name desktop.ini -print0 | xargs -0 -I {} rm -vf {}

If you just want to delete the desktop.ini files in a specific .git directory, then you can use the following command:

find <.git_directory> -type f -name desktop.ini -print0 | xargs -0 -I {} rm -vf {}
JesusIniesta
  • 10,412
  • 1
  • 35
  • 28
1

I had same issue. i follow following steps

1)switch your branch which having issue to other branch

2) delete that branch

3) checkout again.

Note:- You can stash you uncommitted changes and put it back again.

1

Got this issue when trying to clone from a git bundle created file, none of the other answers worked because I couldn't clone the repo (so git gc and removing/editing files was out of the question).

There was however another way to fix this - the source file of a .bundle file was begining with:

# v2 git bundle
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d HEAD
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d refs/heads/master
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d refs/heads/master

PACK.......p..x...Kj.0...: (and so on...)

Simply removing the fourth line with vim fixed the issue.

Krzysztof Bociurko
  • 4,575
  • 2
  • 26
  • 44
1
 # remove the reference file of the branch "lost"
 rm -fv ./.git/refs/remotes/origin/feature/v1.6.9-api-token-bot-reader
 
 # git clear everything 
 clear ; git reset HEAD --hard ; git clean -xdf ; 

 # subdue the current branch and pull all changes from the remote
 clear ; git fetch --all -p ; git pull --all --rebase ; clear ; git branch -a

 # git will "know" how-to handle the issue from now on
 #     From github.com:futurice/senzoit-www-server
 # * [new branch]      feature/v1.6.9-api-token-bot-reader ->
 # origin/feature/v1.6.9-api-token-bot-reader

 # and push your local changes
 git push
Yordan Georgiev
  • 5,114
  • 1
  • 56
  • 53
1

I used git prune origin and that did the work.

TheFakeCake
  • 164
  • 2
1

Writing down a specific case that might cause this problem.

One day I pushed a branch named "feature/subfeature", while having "feature" branch on remote.

That operation worked fine without any error on my side, but when my co-workers fetched and/or pulled any branch, they all had the exact same error message unable to update local ref, cannot lock ref 'refs/remotes/origin/feature/subfeature.

This was solved by deleting feature branch on remote(git push --delete origin feature) and then running git remote prune origin on my co-workers' repo, which generated messages including * [pruned] origin/feature.

So, my guess is git fetch was trying to create subfeature ref in feature folder on git internally(.git/...), but creating folder failed because there was feature ref already.

ik1ne
  • 1,041
  • 15
  • 20
1

Try this: git branch --unset-upstream

I was facing the problem earlier but I just solved it when I saw this command on the terminal.

Alex Maina
  • 443
  • 4
  • 10
1

for me the git-gc and prune solutions didn't work. I also couldn't delete the ref file of the problematic branch since it didn't exist locally when I inspected the ref folder.

since I didn't have any important information locally that wasn't on remote, I've just deleted the local repo and cloned it again. that made the pull redundant since after git clone the repo is already up to date.

Daniel
  • 1,895
  • 9
  • 20
0

I had the same problem with composer update. But for me it only worked after I cleared the composer cache and after deleting the content of the vendor folder:

rm -rf vendor/*
git gc --prune=now
git pull
composer clear-cache
composer update my/package
ownking
  • 1,956
  • 1
  • 24
  • 34
0

I had this issue while using SourceTree. I tried to pull again and it worked. I think I Was witching branches (checkout) too fast :).

My situation is a bit different from the poster's because my repository has been relatively cooperative, without any apparent corruption.

Pysis
  • 1,452
  • 2
  • 17
  • 31
0

Had the same msg but with a directory, got a failed msg on pull.

git --prone did not help me either. Turns out there was a file with the same name as a directory created remotely.

Had to go to .git\logs\refs\remotes\origin and erase the locale file - then pull again, all good.

Asaf Maoz
  • 675
  • 3
  • 6
  • 23
0

Just ran into the problem today.

Troubleshooting method: With SourceTree on Windows Servers, you may try to run it as an Administrator. That fixes my problem of "unable to update local ref" on Atlassian Source Tree 2.1.2.5 on a Windows Server 2012 R2 in domain.

If you can too replicate this situation, it proves that the problem is caused by permission issue. It's better to drill down and find the root cause - probably some particular files are owned by other users and such - otherwise there's an unwelcome side-effect: you'll have to run SourceTree as Administrator for the rest of eternity.

Lionet Chen
  • 832
  • 11
  • 26
  • Well, I wouldn't recommend this. You will end up with even more files with incorrect permissions. And you will need to run everything that manipulates with repository files as an administrator. Isn't it better to simply fix the permissions in the first place? – David Ferenczy Rogožan Jul 24 '18 at 16:53
  • You're right. But only after making it work as an Admin had I figured out it was the permission issue. So this was a step in my diagnosing procedure, not a perfect solution per se. – Lionet Chen Jul 25 '18 at 01:06
  • Sure. But many users may just take your answer as a solution without really knowing the consequences. Maybe better if you add the fixing of the permissions as a suggested solution. – David Ferenczy Rogožan Jul 25 '18 at 12:15
0

Faced the same issue when repository was deleted and created with the same name. It worked only when I re-set the remote url like below;

git remote set-url origin [GIT_REPO_URL]

Verify the remote url:

git remote -v

Now, all commands should work as usual.

Ricky Boy
  • 723
  • 7
  • 7
0

We got this issue when a developer on Mac created a branch with a greater than ">" symbol in the branch name.

That caused problems in TeamCity, and on local Windows based computers running SourceTree. BitBucket let it through without any problems.

To resolve the user removed the branch and recreated it. Which was nice and easy.

dylanT
  • 1,080
  • 1
  • 13
  • 26
0

In case anyone finds this useful, I was getting this issue chronically, although not constantly, and it was because I had git directory within Dropbox, removed it from Dropbox and all was fine.

agorapotatoes
  • 311
  • 2
  • 16
0

I tried everything else however none worked for me apart from this solution. Just delete git's remotes folder from your project directory. In my case it was.

.git/refs/remotes/
Vijay E
  • 829
  • 10
  • 14