git push remote repo
I have a local working copy repo and a remote repo on my flash drive. I've pushed to the flashdrive before but i can't seem to do it again.
here i went into my remote repo on my flashdrive to see which branch i was on and looked at the log. Then i went back into my working copy local repo, edited a file, added that file, made a commit and attempted to push it my flashdrive but it didn't work. Can any tell what i'm doing wrong?
David-Adamss-MacBook-Pro:~ davidadams$ cd /volumes/thumbdrive/repo/releventz
David-Adamss-MacBook-Pro:releventz davidadams$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
nothing to commit (working directory clean)
David-Adamss-MacBook-Pro:releventz davidadams$ git branch
* master
David-Adamss-MacBook-Pro:releventz davidadams$ git log
commit 65328c9603f62b7a2058f38fb441605b0c4c431e
Author: David Adams <adams.david.10@gmail.com>
Date: Wed Jun 29 23:30:40 2011 -0500
third commit
commit b3883fa933609db634b98d747299c1e9c96e8269
Author: David Adams <adams.david.10@gmail.com>
Date: Wed Jun 29 23:10:53 2011 -0500
second commit
commit 54832381a6fe898408c9e07bc8409a2982ec6274
Author: David Adams <adams.david.10@gmail.com>
Date: Wed Jun 29 22:20:04 2011 -0500
changed checklist.php
commit 1955664689313a589543576477e0a134f26cc313
Author: David Adams <adams.david.10@gmail.com>
Date: Wed Jun 29 22:12:53 2011 -0500
first releventz commit
David-Adamss-MacBook-Pro:releventz davidadams$ cd
David-Adamss-MacBook-Pro:~ davidadams$ cd
David-Adamss-MacBook-Pro:~ davidadams$ cd /applications/mamp/htdocs/releventz
David-Adamss-MacBook-Pro:releventz davidadams$ git status
# On branch master
nothing to commit (working directory clean)
David-Adamss-MacBook-Pro:releventz davidadams$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modifie开发者_如何学God: application/libraries/calendarclass.php
#
no changes added to commit (use "git add" and/or "git commit -a")
David-Adamss-MacBook-Pro:releventz davidadams$ git add .
David-Adamss-MacBook-Pro:releventz davidadams$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: application/libraries/calendarclass.php
#
David-Adamss-MacBook-Pro:releventz davidadams$ git commit -m 'blah blah'
[master 853232d] blah blah
1 files changed, 1 insertions(+), 1 deletions(-)
David-Adamss-MacBook-Pro:releventz davidadams$ git push flashdrive master
Counting objects: 17, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (12/12), done.
Writing objects: 100% (12/12), 1.89 KiB, done.
Total 12 (delta 8), reused 0 (delta 0)
Unpacking objects: 100% (12/12), done.
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 t
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int
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 som
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, se
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
gTo /volumes/thumbdrive/repo/releventz
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/volumes/thumbdrive/repo/releventz'
You're not allowed to push to another repository that has checked out code. Git is refusing to update it.
If you really need a backup repo on the flash drive and you'll never edit things in it, then make it a bare repo instead.
If you are using it as a second location to edit things, then go into that repo and pull from your disk-based one instead. IE, always pull into an actively used repository, and never push.
[yes you can get around this, but you shouldn't]
Today i had the same error.and i fix it whit method like Bill Door's answer. Maybe you can do like this:
David-Adamss-MacBook-Pro:~ davidadams$ cd /volumes/thumbdrive/repo/releventz
David-Adamss-MacBook-Pro:~ davidadams$ git checkout subbranch
David-Adamss-MacBook-Pro:~ davidadams$ cd /applications/mamp/htdocs/releventz
David-Adamss-MacBook-Pro:~ davidadams$ git push flashdrive master
Wes has offered two good answers. Another solution is to create a second branch. Go to your source repository and checkout the second branch. You can now push to the master branch from you work repository.
cd master_repo
git checkout -b stepaside
cd work_repo
git push
Subsequent pushes you can replace with
cd master_repo
git checkout stepaside
cd work_repo
git push
Another option is to not have the full non-bare (or even bare) repo on the flashdrive (because it involves being sure that a lot of files are properly copied on a remote storage device), but to have or to update a bundle.
A git bundle is one file (much easier to copy over an USB drive).
And you can pull from that one file, in order to recreate a full-fledged repo anywhere you need to.
See "How to synchronize two git repositories" as an illustration.
精彩评论