How to copy a local repository to remote server using git?

后端 未结 2 623
执念已碎
执念已碎 2021-01-31 11:34

I\'m trying to use git to deploy my local code in my remote server.

So here is what I\'ve done in my local folder mywebsite/ :

git init
git add .
         


        
相关标签:
2条回答
  • 2021-01-31 11:42

    This will answer your question

    http://www.saintsjd.com/2011/01/what-is-a-bare-git-repository/

    In bare repository you don't need to have source.

    0 讨论(0)
  • 2021-01-31 12:07

    You've created a remote repository without a working directory (which is the purpose of the --bare option). What you need to do next is clone that remote repository into your website directory. I use the same approach; I have a ~/git directory with one or more bare git repositories and then clones for one or more web sites. Your steps could be:

    # locate your bare repository in a 'git' directory
    remote$ mkdir ~/git; mkdir ~/git/mywebsite.git; cd ~/git/mywebsite.git; git init --bare
    
    # set this up as your remote
    local$ git remote add origin ssh:.../git/mywebsite.git
    local$ git push origin ...
    
    # on the remote, clone into your working website
    remote$ cd ~/public_html
    remote$ git clone ~/git/mywebsite.git mywebsite
    

    Using this approach you can develop locally, push to remote as often as you like and then, when you are ready, git pull on the remote to actually update the website.

    0 讨论(0)
提交回复
热议问题