Note: This the third video in the Git for beginners series. Watch the first video here.
注意:这是Git初学者系列的第三个视频。 在这里观看第一个视频 。
In Git terminology, we call the Git repository on your computer a local repository.
用Git术语,我们将您计算机上的Git存储库称为本地存储库。
A Git remote is the same repository stored somewhere else on the internet. It can serve as a backup. If your computer crashes, you can always get the latest version from the remote back onto your computer.
Git遥控器是与Internet上其他地方存储的相同的存储库。 它可以用作备份。 如果您的计算机崩溃了,您始终可以将最新版本从遥控器上重新下载到计算机上。
Before we talk about Git remotes, we have to talk about different services that provide you with Git remotes. Let’s look at some examples.
在谈论Git遥控器之前,我们必须讨论为您提供Git遥控器的不同服务。 让我们看一些例子。
Git服务之间的差异 (Differences between Git services)
There are no differences between these three services where Git itself is concerned.
与Git本身有关的这三种服务之间没有区别。
The only differences between the services are their popularity, web interface, and pricing.
服务之间的唯一区别是它们的受欢迎程度,Web界面和价格。
Many people like to use Github because Github is the most popular one out of the three. This is also why most open source projects are hosted on Github. (Note: open source projects can also be hosted on Bitbucket and Gitlab as well).
许多人喜欢使用Github,因为Github是三者中最受欢迎的一种。 这也是为什么大多数开源项目都托管在Github上的原因。 (注意:开源项目也可以托管在Bitbucket和Gitlab上)。
Sometimes you may want to create private repositories. A private repository is a Git repository that can only be read by you and the people you give permission.
有时您可能想创建私有存储库。 私有存储库是一个Git存储库,只能由您和您授予权限的人员读取。
If you want to create private repositories, you might want to consider Bitbucket or Gitlab. They let you create private repositories for free.
如果要创建私有存储库,则可能要考虑使用Bitbucket或Gitlab。 他们让您免费创建私人存储库。
If you want to create a private repository on Github, you need to pay $7 a month.
如果要在Github上创建私有存储库,则需要每月支付$ 7。
This article shows you how to set up a remote on Github. The other services follow the same instructions.
本文向您展示了如何在Github上设置遥控器。 其他服务遵循相同的说明。
在Github上创建存储库 (Creating a repository on Github)
Sign in to Github. Create an account if you don’t have one already.
登录到Github。 如果您还没有帐户,请创建一个。
Once you sign in, you’ll see a plus (+) button on the right-hand corner of the page. Click on this plus button and select “new repository.”
登录后,您会在页面右上角看到一个加号(+)。 单击此加号按钮,然后选择“新存储库”。
To create a new repository, you need to give your repository a name.
要创建新的存储库,您需要给存储库命名。
The description provides details so other people can understand your project. It is optional. You can leave it out for now.
该说明提供了详细信息,以便其他人可以理解您的项目。 它是可选的。 您可以暂时忽略它。
Set the project to public or private, depending on what you want.
根据您的需要将项目设置为公共或私有。
Then, ignore the rest and click on the create repository button.
然后,忽略其余部分,然后单击“创建存储库”按钮。
Once you click on create repository, you’ll come to a page with some Git instructions.
单击创建存储库后,您将进入包含一些Git指导的页面。
Ignore these instructions for now. This knowledge requires you to use the Git command line. You’re going to learn how to do that in a few lessons.
现在忽略这些说明。 该知识要求您使用Git命令行。 您将在几节课中学习如何做到这一点。
For now, we want to link up our local repository in Fork to the remote repository we just created.
现在,我们想将Fork中的本地存储库链接到我们刚创建的远程存储库。
Copy the URL you see on the page.
复制您在页面上看到的URL。
Make sure you select SSH (not HTTPS!).
确保选择SSH(不是HTTPS!)。
SSH lets you push (put things into the remote repository) and pull (copy the remote back to your local) without entering your Github username and password every time. It makes things a lot easier.
SSH使您无需每次都输入您的Github用户名和密码即可推送(将内容放入远程存储库)和推送(将远程文件复制回本地)。 它使事情变得容易得多。
Next, open the project in Fork and click the Push button.
接下来,在Fork中打开项目,然后单击Push按钮。
It is the fourth button from the left. It looks like an arrow that goes upwards.
这是左侧第四个按钮。 它看起来像一个向上箭头。
Once you click on the push button, Fork will ask you to select a branch and a remote to push to.
单击按钮后,Fork会要求您选择一个分支和一个要推入的遥控器。
In this case, our branch will be master (because we only have one branch).
在这种情况下,我们的分支将是主分支(因为我们只有一个分支)。
We need to add the remote we just created. To add the remote, click on the select box and select add remote.
我们需要添加刚刚创建的遥控器。 要添加遥控器,请单击选择框,然后选择添加遥控器。
Next, you need to name your remote.
接下来,您需要命名您的遥控器。
The default name for most remotes will be origin. If you have multiple remotes, you will want to rename the remote according to where they are from (like Github, Heroku, and Bitbucket).
大多数遥控器的默认名称将是原始名称。 如果您有多个遥控器,则需要根据遥控器的来源(如Github,Heroku和Bitbucket)重命名。
The repository URL should be the URL you copied from Github.
存储库URL应该是您从Github复制的URL。
Select Add new remote when you’re done.
完成后,选择添加新的遥控器。
第一次推入遥控器 (Pushing to the remote for the first time)
When you push your files onto the remote for the first time, make sure the create tracking reference checkbox is checked.
首次将文件推送到遥控器时,请确保已选中“创建跟踪参考”复选框。
A tracking reference tells Git to track the current branch (master in this case) and to push or pull to the same branch on the remote.
跟踪参考告诉Git跟踪当前分支(在这种情况下是主分支),并将其推或拉到遥控器上的同一分支。
If you don’t create a tracking reference, you will need to specify which branch to push to (or pull from) every time.
如果您没有创建跟踪参考,则需要指定每次要推送(或从中提取)的分支。
Note: if branching sounds foreign to you right now, don’t worry about it. We’ll talk about branching in a later lesson. For now, just remember you need to create a tracking reference.
注意:如果分支机构现在听起来对您来说很陌生,请不要担心。 我们将在下一课中讨论分支。 现在,请记住您需要创建一个跟踪参考。
Once that is checked, you can click push and Fork will push your project onto Github.
选中后,您可以单击“推送”,Fork将把您的项目推送到Github上。
Once it is pushed, you can look at the All Commits section. (In other Git clients, that will be Git History).
推送完成后,您可以查看“所有提交”部分。 (在其他Git客户端中,将是Git历史记录)。
In all commits, you’ll see two tags. One is called master
(the master branch on our computer). And the other is called origin/master
(the master branch on the remote named origin). In this case, our origin is Github, so origin/master
refers to the master branch on Github.
在所有提交中,您将看到两个标签。 一种叫做master
(我们计算机上的master分支)。 另一个称为origin/master
(远程名为origin的master分支)。 在这种情况下,我们的起源是Github,因此origin/master
是指Github上的master分支。
When these two tags are on the same commit, it means the files we have on our local master branch is the same as the files we have on Github’s master branch.
当这两个标记处于同一提交时,这意味着我们在本地master分支上拥有的文件与我们在Github的master分支上拥有的文件相同。
You can verify this is true if you go back to the page where you got the Git remote URL from. Refresh this page and you’ll see what you’ll usually see on Github (a project page).
如果您返回获取Git远程URL的页面,则可以验证这是正确的。 刷新此页面,您将看到在Github(项目页面)上通常会看到的内容。
If you look at the files, you’ll notice that the files are exactly the same as the files you have on your computer.
查看这些文件时,您会注意到这些文件与计算机上的文件完全相同。
第二次推送 (Pushing for the second time)
Subsequent pushes are much easier.
随后的推送更加容易。
Let’s say we make a change to our repository. This time, we want to create a README.md
file. A README.md
file shows up the Git project page and helps people understand what the project is about.
假设我们对存储库进行了更改。 这次,我们要创建一个README.md
文件。 README.md
文件将显示Git项目页面,并帮助人们了解项目的含义。
You want to create a README.md
file for every repository you create.
您要为您创建的每个存储库创建一个README.md
文件。
Once we have created the file, we’ll see the changes in Fork if we click on the changes tab.
创建文件后,如果单击更改选项卡,我们将在Fork中看到更改。
As before, we want to stage the file and commit the file. In this case, the commit message can be “Create Readme.md”.
和以前一样 ,我们要暂存文件并提交文件。 在这种情况下,提交消息可以是“ Create Readme.md”。
When you create a new commit, take a look at the sidebar on the left. You’ll see a number, one, and an arrow that points upwards beside the master branch.
创建新提交时,请查看左侧的侧栏。 您会在主分支旁边看到一个数字,一个和一个向上指向的箭头。
This tells us our master branch is one commit ahead of the remote branch. This means our master branch is more up to date compared to the remote branch.
这告诉我们我们的主分支比远程分支领先一个提交。 这意味着与远程分支相比,我们的master分支是最新的。
If you look at the Git history, you can the “Create readme.md” commit is on the local branch, but this commit did not make it to the remote yet.
如果查看Git历史记录,则可以在本地分支上执行“ Create readme.md”提交,但是此提交尚未到达远程。
To push the new commit onto the remote, you need to click on the push button again.
要将新提交推送到遥控器上,您需要再次单击该按钮。
Then, click push once more.
然后,再次单击“推送”。
That’s it.
而已。
Once the commit is pushed to the remote branch, you can see that the origin/master
tag gets moved to the same commit as the master
tag.
一旦被推到远程分支的提交,你可以看到, origin/master
标签被移动到同犯的master
标签。
To prove that this is working, you can refresh the Github repository page and you’ll be able to see your new README.md
file!
为了证明这是README.md
,您可以刷新Github存储库页面,然后就可以看到新的README.md
文件!
结语 (Wrapping up)
A Git remote is kind of like a backup that is stored on someone else’s computer. To create a Git remote, you can use one of the popular services like Github, Bitbucket, and Gitlab.
Git遥控器有点像备份,它存储在其他人的计算机上。 要创建Git远程服务器,可以使用Github,Bitbucket和Gitlab等流行的服务之一。
Create a remote repository, then link your local repository to the remote repository. When you link them up, you can push to the remote repository.
创建一个远程存储库,然后将本地存储库链接到远程存储库。 将它们链接起来后,可以推送到远程存储库。
Thanks for reading. Did this article help you in any way? If I did, I hope you consider sharing it; you might just help someone who felt the same way you did before reading the article. Thank you.
谢谢阅读。 本文对您有任何帮助吗? 如果我做到了, 我希望你考虑分享它 ; 您可能只是帮助与您在阅读本文之前一样的人。 谢谢。
This article was originally posted at my blog.Sign up for my newsletter if you want more articles to help you become a better front-end developer.
本文最初发布在我的博客上 。 如果您想要更多文章来帮助您成为更好的前端开发人员,请注册我的新闻通讯 。
翻译自: https://www.freecodecamp.org/news/how-to-push-to-a-git-remote-repository-570d2712b62f/