如何从Windows克隆git仓库到Linux?

3

我之前在Linux服务器上保留了一个裸的Git存储库,并在本地Windows笔记本电脑上使用工作副本进行开发(使用TortoiseGit通过ssh同步到服务器)。由于某些原因,服务器版本被删除/丢失,因此我想使用Windows机器上本地工作副本中的最新提交来重新创建服务器上的存储库。

如何以最佳方式从Windows工作副本创建此新的远程裸存储库副本并复制到远程Linux服务器?

4个回答

5

您可以使用以下命令重新创建 Linux 服务器存储库:

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

在本地副本上,假设远程URL相同,则执行以下操作:

git push origin <branch refspec>

例如
git push origin master

注意:如果远程URL发生变化,您可以使用
git remote set-url origin <new-url>

2
值得注意的是,如果您有许多分支,则使用git push origin --all后跟git push origin --tags比逐个推送分支和标签更容易。 - PerlDuck

2

只需在服务器上创建仓库,然后将其作为远程仓库添加到您的本地仓库中(如果不是以前的相同位置),并将更改推送到它。


1
跟随以下步骤:

  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:

    enter image description here

  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.

    enter image description here

假设那就是全部。^__^

0

在你的Windows电脑上:

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

以上命令将创建名为local-working-copy-of-the-repo.git的本地工作副本文件夹。
现在将该文件夹(裸仓库)复制到Linux服务器上。
希望这可以帮助到你。

1
这不是最好的主意,因为在Windows上创建存储库会在.git/config中创建一些与CR / LF和文件系统问题相关的设置(它们的大小写[不]敏感性,缺少“x”标志)。最好在Linux上创建一个空的裸仓库,然后将其推送到远程。 - PerlDuck

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接