获取远程仓库 Git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18866880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:59:35  来源:igfitidea点击:

Get remote repository Git

gitgit-clonegit-remote

提问by Ray

I am almost newby in Git and just read Git book from the official site. I try understand difference between next cases.

我几乎是 Git 新手,只是从官方网站上阅读了 Git 书籍。我试着理解下一个案例之间的区别。

git init Project
git remote add Project [some-url]

and

git clone [some-url]

And what is a preferable approach?

什么是更好的方法?

回答by abhshkdz

There is no question of preference. These are commands for 2 entirely different purposes.

没有偏好的问题。这些是用于 2 个完全不同目的的命令。

git init Project
git remote add Project [some-url]

git initinitializes a directory as a Git repository

git init将目录初始化为 Git 存储库

This is used when you are starting work on a newproject, not continuing work on an existing project under version control.

当您开始在项目上工作,而不是在版本控制下继续在现有项目上工作时使用。

git clone [some-url]

git clonecopies a git repository so you can add to it

git clone复制一个 git 存储库,以便您可以向其中添加

This would clone an existingrepository off the remote to your machine, so that you can work on it.

这会将现有存储库从远程克隆到您的机器,以便您可以对其进行处理。

Links to help you out:
* git init
* git clone

帮助你的链接:
* git init
* git clone

回答by juco

git clone [something]is the equivalent to:

git clone [something]相当于:

git init Project
git remote add origin [some-url]
git pull origin master

It's a little strange to call your remote Project, but perhaps that was a typo. Either way, you can specify -oto name the remote something else when cloning, from the man page:

调用您的 remote 有点奇怪Project,但也许这是一个错字。无论哪种方式,您都可以-o在克隆时从手册页指定将远程命名为其他名称:

Instead of using the remote name origin to keep track of the upstream repository, use .

不要使用远程名称 origin 来跟踪上游存储库,而是使用 .

回答by Abhijith S

If you are going to work on a new project(for you) which is actually an existing project then you have to download that project. In terminal you can download it by typing

如果您要处理一个新项目(为您),它实际上是一个现有项目,那么您必须下载该项目。在终端中,您可以通过键入来下载它

    git clone <url>

and work on this project and then push the updates to remote.

并在此项目上工作,然后将更新推送到远程。

And, If you are going to create a new project of your own. Then create a remote repository and follow these simple steps. You will be asked to give your github username and password while adding to remote origin and then push the changes. If you have added README remote then you have to pull changes

而且,如果您要创建自己的新项目。然后创建一个远程存储库并按照这些简单的步骤操作。添加到远程源时,系统会要求您提供 github 用户名和密码,然后推送更改。如果您添加了 README 远程,那么您必须拉取更改

    git pull origin <branchname(eg:master)>

and then push your local changes.

然后推送您的本地更改。