Unable to push to repository

I'm new to Sourcetree, so bear with me. I set up a repository on my desktop computer in the office for my department to use to share files. The repository is located here: //ANNALISA_DESKTO/Users/Box Works/Documents/Electrical Department

I have cloned the repository on my laptop and a co-workers laptop. My clone is located here: C:\Users\boxworks\Documents\Electrical Department

I can make changes to the repository on my desktop and pull them onto my laptop, but I cannot make changes on my laptop and push to the repository. I get an error:

"git -c diff.mnemonicprefix=false -c core.quotepath=false push -v --tags origin master:master Pushing to //ANNALISA_DESKTO/Users/Box Works/Documents/Electrical Department

remote: error: refusing to update checked out branch: refs/heads/master [K

remote: error: By default, updating the current branch in a non-bare repository [K

remote: error: is denied, because it will make the index and work tree inconsistent [K

remote: error: with what you pushed, and will require 'git reset --hard' to match [K

remote: error: the work tree to HEAD. [K

remote: error:  [K

remote: error: You can set 'receive.denyCurrentBranch' configuration variable to [K

remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into [K

remote: error: its current branch; however, this is not recommended unless you [K

remote: error: arranged to update its work tree to match what you pushed in some [K

remote: error: other way. [K

remote: error:  [K

remote: error: To squelch this message and still keep the default behaviour, set [K

remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. [K To //ANNALISA_DESKTO/Users/Box Works/Documents/Electrical Department  ! [remote rejected] master -> master (branch is currently checked out) error: failed to push some refs to '//ANNALISA_DESKTO/Users/Box Works/Documents/Electrical Department' "


So I'm gathering that I'm supposed to be operating on my desktop from a clone instead of the actual repository? I'm not sure if I'm on the right page here. Can anyone offer some insight?


Thanks. smile

1 answer

1 accepted

3 votes
Accepted answer

Hi Annalisa,

This error is showing up because you didn't create the original repo as a bare repository, thus it's "protected" in a way you can't just push to it.

You can do as the error message says and set receive.denyCurrentBranch in the server side, where this repository is originally located. You can do this by navigating to the repository in the original location and running:

git config receive.denyCurrentBranch ignore

For reference, I took this from http://stackoverflow.com/questions/3221859/cannot-push-into-git-repository


Gustavo Refosco

Hi Gustavo. Thank you for the reply. Do I run this in a command line prompt? I'm unsure where to run this (I am using windows). Thanks!

Hi Annalisa, Exactly, on the server from which the original repository is coming from you need to navigate to the repository and execute the command - I'm assuming you will be able to execute git commands in the command line. Regards, Gustavo Refosco

You also want to be careful about using the copy of the repository that is on your own computer to make changes. Git is not prepared for you to be working on a branch that others are pushing changes to.

Gustavo, when I run this command from the command line in the same location as the repository, I get this error: " 'git' is not recognized as an internal or external command, operable program or batch file."

Seth, that is exactly what I am doing. Is there another way to do it?? The repository needs to be on this computer. :/

I would recommend having two repositories on your computer. First, create a bare repository (I'll call it the "central repo"); your team members should use the central repo as their remote. Second, create a local (non-bare) clone of the bare repository for your own work (i'll call it your "working repo"). Your working repo will be able to push and pull to/from the central repo as a remote repo, even though it is on the same machine.

I deleted my repositories and started over. When I try to create a bare repository in the command line in my desired directory, I typed in "git init --bare PATH". But I get an error saying "git is not recognized as an internal or external command." What am I doing wrong???

Hi Annalisa, This is basically a message that tells you Git isn't installed or isn't properly set in your path, thus it can't be found in the command line. You may refer to http://stackoverflow.com/questions/4492979/git-is-not-recognized-as-an-internal-or-external-command for further help to set this.

That link did the trick! Thank you. I just had to add my git.exe path to a setting in my computer. Now I am able to push & pull from both my laptop and my desktop. I appreciate all the help!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 23, 2018 in Sourcetree

Tip from the team: configure your repos for hosting goodness!

Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...

979 views 4 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you