English 中文(简体)
Git-将存储库与签出分支同步的最简单方法
原标题:Git - simplest way to sync a repository with a checked out branch
  • 时间:2010-10-25 00:01:20
  •  标签:
  • git

我的工作流程基本上是:

  • Create a repo on my desktop PC
  • Do some work on it and commit changes
  • Clone onto my laptop
  • Work on that, commit changes

现在我想将更改与我的桌面同步。尝试git push desktop.local:~/my repo将失败,因为主分支已经签出。我知道有两种解决方案:

  1. 在我电脑上的另一个目录中创建第三个裸存储库,并从那里更新两个工作副本。但一个有两个工作副本的中央存储库听起来像。。。SVN!除了chussier,因为我不能只使用svn-updatesvn-commit来与这个中央存储库同步-需要额外的步骤才能从提交到Git工作副本的更改中实际更新中央回购。

  2. 推送到一个单独的分支并将该分支合并到我的桌面工作副本中。这还不错,但是。。。

…我不明白的是:如果我只是SSH到台式电脑并发布git pull笔记本电脑。local:~/my repo,它就可以工作了!它将提交的更改拉入并更新已签出的主分支,不询问任何问题。为什么t<code>git push</code>本身不能做到这一点?

因此,我的问题是:是否有一个与ssh相同的命令——进入我的台式电脑并发出pull

最佳回答

The problem is when you are trying to push you are doing 2 actions at the same time. The first one is to update git tree and the second one is to update the working directory on your laptop. So there is a kind of implicit checkout in the push process and git refuse to do it and it s right. Imagine what will happen if someone was actually working on your desktop PC. When you do an SSH things are different, you are in your working directory, you are responsible for everything you do, and so, can do what ever you want , removing file , "pulling". So it seems normal in a way, that pushing doesn t allow you (by default) to mess up the remote computer.

Update

如果你将receive.denyCurrentBranch设置为忽略,你可以推送,但你仍然必须将你的工作目录与“最新”版本的代码(你刚刚推送的代码)“同步”。这意味着你仍然有两个命令在每台计算机上运行一个

如果你真的只想运行一个命令,请使用shell的强大功能,并创建一个别名,从桌面计算机进行git pull操作

alias remote_pull=ssh <desktop> "cd <path>; git pull"
问题回答

您可以将receive.denyCurrentBranch设置为警告以允许推送到您的台式电脑。但是,这很危险。如果你的台式电脑中有一些提交,这个推送会引起混淆。

以下是receive.denyCurrentBranch的手册供您参考。

  receive.denyCurrentBranch
      If set to true or "refuse", receive-pack will deny a ref update to
      the currently checked out branch of a non-bare repository. Such a
      push is potentially dangerous because it brings the HEAD out of
      sync with the index and working tree. If set to "warn", print a
      warning of such a push to stderr, but allow the push to proceed. If
      set to false or "ignore", allow such pushes with no message.
      Defaults to "refuse".




相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签