Git - 将存储库与检出分支同步的最简单方法 [英] Git - simplest way to sync a repository with a checked out branch

查看:135
本文介绍了Git - 将存储库与检出分支同步的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作流程基本上是:


  • 在我的台式电脑上创建一个回购站点

  • 克隆到我的笔记本电脑上

  • 处理它并提交更改



现在我想与桌面同步更改。尝试 git push desktop.local:〜/ my-repo 会失败,因为主分支已经被签出。我知道这两个解决方案:


  1. 在我的电脑的另一个目录中创建第三个裸仓库,并更新两个工作副本从那里。但是一个中央仓库有两个工作副本,检出声音就像...... SVN!除了笨拙,因为我不能只用 svn update svn commit 来与这个中央资料库同步 - 额外的步骤需要实际更新提交给Git工作副本的更改中的中央回购。

  2. 推送到一个单独的分支并在我的桌面上合并该分支复制。这并不算太坏,但... ...

...我不明白的是这样的:如果我只是SSH到台式电脑,并发行 git pull laptop.local:〜/ my-repo ,它的工作原理!它将提交的更改并更新已签出的主分支,而不会询问任何问题。为什么不能 git push 自己做这件事?



所以,这里是我的问题:是否有一个命令相同于 ssh - 进入我的台式电脑并发出一个

解决方案

问题是当你试图推动你同时做2个动作时。
第一个是更新git树,第二个是更新笔记本电脑上的工作目录。所以在推送过程中有一种隐含的结账,git拒绝这么做,这是正确的。
想象一下如果有人真的在台式电脑上工作会发生什么。
当你做一个SSH时,事情是不一样的,你在你的工作目录中,你对你所做的一切负责,所以,你可以做你想做的事,删除文件,拉。所以在某种程度上这似乎很正常,推送不允许你(默认情况下)弄乱远程计算机。



更新



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



如果您真的只想运行一个命令,请使用shell的权限并创建一个别名,从桌面计算机获取git pull

  alias remote_pull = ssh< desktop> cd< path> ;; git pull


My workflow is basically:

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

Now I want to synchronise the changes with my desktop. Trying git push desktop.local:~/my-repo will fail, because the master branch is already checked out. I know of two solutions to this:

  1. Create a third, bare repository in another directory on my PC and update both working copies from there. But a single central repository with two working copies checked out sounds like... SVN! Except clumsier, because I can't just use svn update and svn commit to synchronise with this central repository — extra steps are required to actually update the central repo from changes committed to a working copy in Git.

  2. Push to a separate branch and merge that branch in on my desktop working copy. This isn't too bad, but...

...what I don't understand is this: if I just SSH to the desktop PC and issue git pull laptop.local:~/my-repo, it works! It pulls the committed changes in and updates the checked out master branch, no questions asked. Why can't git push do this itself?

So here's my question: is there a command that works the same as ssh-ing in to my desktop PC and issuing a 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

If you are setting the receive.denyCurrentBranch to ignore , you can push but you still have to "synchronize" your working directory with the "latest" version of the code (the one you just pushed). That mean you still have 2 commands to run one on each computer

If you really want to run only one command use the power of the shell and create an alias which do a git pull from the Desktop computer

alias remote_pull=ssh <desktop> "cd <path>; git pull"

这篇关于Git - 将存储库与检出分支同步的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆