在使用了多年的 svn
和 cvs
之后,我刚刚开始使用 git
。我掌握了大部分内容,但我觉得我的常用使用顺序不是最佳的。
我的设置:
我使用来自 origin
服务器的本地克隆存储库在我的工作站上进行开发,在我的项目中,它被视为“主”存储库。我定期执行 git fetch
,检查新更新,然后 git merge
merge 它们(如果相关)。
但是,当我处理并检查我的疑问所在的代码分支时。
我使用的一个常见序列:
git branch somenewbranch
git checkout somenewbranch
... work work work ...
git add [changed files]
git commit
git checkout master
git merge somenewbranch
git branch -d somenewbranch
以下是我认为可以优化的地方:
git push origin master:blahblah # This won't let me push to master branch
ssh origin
cd repodir
git merge blahblah
git branch -d blahblah
logout
git status # this shows me I'm still ahead
git pull origin # to bring them back in sync
git remote show origin # shows I have a stale blahblah branch
git remote prune origin # cleans that up
现在我已经同步了它们。这似乎有很多额外的步骤来同步我的本地和“主”存储库。
有人可以帮助我优化使用吗?
谢谢。
编辑:如果我不执行单独的分支,我会收到一条错误消息:
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.
最佳答案
如果您只是在更改后使用 git push
,并且您在 origin/master
之前,那么一切都应该顺利进行。为什么要明确指定一个不同的远程分支来将本地主分支推送到?
您是否因为提示已 checkout 分支而无法推送到原始存储库?如果是这样,你犯了一个常见的错误。您需要使用裸仓库作为源,这样 Git 才能接受更改而不会导致服务器上的工作副本出现问题。
关于git 使用远程 'origin' 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4754523/