Can Git software (e.g. Gitbox, Github, SourceTree) use a remote repo instead of local?

前端 未结 5 984
-上瘾入骨i
-上瘾入骨i 2021-02-09 14:53

I like using Git software to push commits, but the ones I use (Gitbox, Github, SourceTree) all ask for a local repo when adding a new repo to them.

Thing is, my repo is

5条回答
  •  眼角桃花
    2021-02-09 15:35

    Remember, Git is a DVCS. The fact that you don't connect to a remote server to commit stuff is by design.

    What you want to do is have local Git repos that push code to your integration server (the one that actually runs the code). It's like deploying, only you deploy to a test server instead of production.

    This is normally achieved by having a shared Git repository you push to. This repo should be bare. Besides the bare shared repo, you'll want a non-bare clone of the shared Git repo which will serve as your Apache docroot.

    When the shared repo receives a commit, it will make the docroot repo execute git pull.

    This can be achieved by using post-receive hooks on the shared repo.

    The docroot repo is checked out on a specific branch (let's say develop). So even if you commit stuff to other branches and push them, the server won't be affected.

    This allows you to setup multiple deployment repositories, so you could have another branch prod associated with one of those that would actually update production code when you push stuff to it.

    It also allows you to store incomplete / on-going work on a shared branch that doesn't deploy at all, so that you know the thing you've been working on your laptop is safe on the shared repo, even though it can't be sent to the test server because it's not complete and would break the test server, making other people unable to work or something.

    This article goes in detail how to setup all that. I've done it before, it works well.

提交回复
热议问题