简体   繁体   中英

How to clone git repo from Windows to Linux?

I previously kept a bare git repository on a Linux server and a working copy in my local Windows laptop for development (syncing to the server using TortoiseGit over ssh). The server version was deleted/lost so I want to recreate the repo on the server using the latest commit from the local working copy on the Windows machine.

What is the best way to create this new remote bare repo copy on the remote Linux server from the Windows working copy?

You can re-create the linux server repo using

mkdir -p myrepo.git
cd myrepo.git
git init --bare

On the local copy, assuming the remote URL is the same, do

git push origin <branch refspec>

for example

git push origin master

Note: If the remote URL has changed you can use

git remote set-url origin <new-url>

只需在服务器上创建repo,然后将repo添加到本地的repo,如果它与以前的位置不同并推送到它。

Follow these steps:

  1. Create a bare repository on remote.

    I guess the answer provided by ad22 is good enough for you:

     mkdir -p myrepo.git cd myrepo.git git init --bare 

    Otherwise, you need to find out how to create a bare repository on server.

  2. Copy or Memo the URL of that just created bare repository.

    (Of cause, you need to have the right for accessing the URL.)

  3. Add a new remote for your local repository.

    Since you already have a local repository,

    1. Right click in that repository, Click TortoiseGit -> Settings ,
    2. Give the remote a shortname and URL you copied
    3. Add it and apply the setting.

    See:

    在此输入图像描述

  4. Push to remote by right clicking in local repository and click Push item.

  5. In Push dialog,

    1. Select the remote you just added.
    2. Check the Push all branches checkbox if all branches can be public, otherwise you need push each branch one by one.
    3. Check the Include Tags checkbox if you want to push all tags.

    在此输入图像描述

Suppose that's all. ^__^

On your Windows machine:

git clone --bare /path/to/local-working-copy-of-the-repo

The above command will create local-working-copy-of-the-repo.git folder.
Now copy the folder(bare repository) on to the Linux server.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM