Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Git Basics Working With Remote Repositories Pushing and Pulling

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Issue with git push.

I am having issues with the 'push' command, here is my input:

git push origin new_p

I got this error:

error: src refspec new_p does not match any.
error: failed to push some refs to '/Users/CalebKleveter/my_first_repository'

So I tried 'git push' and got this message:

warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 347 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To /Users/CalebKleveter/my_first_repository
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/Users/CalebKleveter/my_first_repository'

So I tried this command:

git config --global push.default matching

Then I ran this command:

git push origin new_p

And I got the same error as before, so I ran 'git push', and got this:

Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 347 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To /Users/CalebKleveter/my_first_repository
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/Users/CalebKleveter/my_first_repository'

Any suggestions?

4 Answers

Tom Bedford
Tom Bedford
15,645 Points

I've not run into this myself but there are a few suggestions here.

The way that I found to solve this is to go to clone repo and run: git config --bool core.bare true then go back to origin repo and push.

This solved the issue

Raymond James Cabrera
Raymond James Cabrera
Courses Plus Student 7,022 Points

You also have to make sure you're on different branches between the two repositories. Git uses it as a defense mechanism to make sure you don't screw anything up between the two. That's why he went back to the 'master' branch in the original repo.

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

I think it worked. Can you tell from the message?

Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 347 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To /Users/CalebKleveter/my_first_repository
 * [new branch]      HEAD -> clone_project
Yohan Dantan
Yohan Dantan
2,370 Points

Caleb Kleveter what did you do to solve this? I'm getting the same error:

remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

I personally don't know what causes it, but I don't have any issues when I am pushing to GitHub or BitBucket, so I am not concerned about it.