Git - simplest way to sync a repository with a checked out branch

前端 未结 2 1437
清酒与你
清酒与你 2021-01-14 14:15

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, co
相关标签:
2条回答
  • 2021-01-14 14:57

    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"
    
    0 讨论(0)
  • 2021-01-14 15:04

    You can set receive.denyCurrentBranch to warn to allow pushing to your desktop PC. However, this is dangerous. If there are some commits in your desktop PC, this push will cause confuse.

    The following is manual of receive.denyCurrentBranch for your reference.

      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".
    
    0 讨论(0)
提交回复
热议问题