git 使用远程 'origin' 存储库

标签 git optimization workflow

在使用了多年的 svncvs 之后,我刚刚开始使用 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 才能接受更改而不会导致服务器上的工作副本出现问题。

Setting up a Private (bare) Repo

How to convert a normal Git repository to a bare one?

关于git 使用远程 'origin' 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4754523/

相关文章:

optimization - Gurobi优化结果写入Csv文件

swift - 如何通过整个模块优化来测试通用性能

python - 推荐的 python 科学工作流程管理工具,定义参数状态而不是时间的依赖性完整性?

git - 如何修改和维护导入的 go 依赖?

Git Push 说明 - 推送什么?

c++ - Python 和 C++ 脚本交互

facebook - 如何在本地、暂存和生产中使用 Facebook Messenger 机器人

workflow - 为什么使用插件注册工具注册自定义工作流程后需要重新启动 CRM 服务器才能正常工作

Git:显示给定工作日的所有提交

git - 如何让 Visual Studio 在 git 下显示 merge 冲突?