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!
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
Matt Corby2,385 Points
Cannot push to origin
I cloned my remote repository named "testRepos" to a new repository named "clonedRepos". I edited a file, committed it, and tried to push clonedRepos to testRepos.
I get a bunch of error messages:
matt@matt-HP-Pavilion-g6-Notebook-PC:~/Documents/clonedRepos$ git push origin Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 320 bytes | 0 bytes/s, done. Total 3 (delta 0), 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 /home/matt/Documents/testRepos ! [remote rejected] master -> master (branch is currently checked out) error: failed to push some refs to '/home/matt/Documents/testRepos'
Maybe it's because I have a branch in testRepos that's not in clonedRepos? Why would that happen? I cloned testRepos when it had a branch in it!
Oziel Perez61,321 Points
I ran into the same problem. Unlike others who say they have a similar problem, I actually have a solution. Did you try switching back to master branch on the origin repository? That's what I did. Then change directory to the cloned repository, switch to your second branch, then 'git push origin <branch-name>' and it should work.
Chris KomaroffCourses Plus Student 13,758 Points
Thanks Oziel Perez for spotting this (and thanks to Julian Gu for asking this as I almost gave up). I went back to "remote" to look at file2 and did not switch back to master like Tommy did. This is a nice thing to learn. The first link below explains. The default "git push" needs to be done on a "bare" repository I think, meaning one with no working directory (never did "git checkout"). One trick is, on the remote, to "git checkout" to a branch other than the one you push to. I think this simulates a bare repo? I can't spot any documentation on this. GitHub probably gets this question about this push error.