github 和git

什么是Git? (What is Git?)

Git is a free, open-source version control software. It was created by Linus Torvalds in 2005. This tool is a version control system that was initially developed to work with several developers on the Linux kernel.

Git是一个免费的开源版本控制软件 。 它由Linus Torvalds在2005年创建。该工具是一个版本控制系统,最初是为了与Linux内核上的多个开发人员一起开发而开发的。

This basically means that Git is a content tracker. So Git can be used to store content — and it is mostly used to store code because of the other features it provides.

这基本上意味着Git是内容跟踪器。 因此,Git可用于存储内容-由于它提供的其他功能,它通常用于存储代码。

Real life projects generally have multiple developers working in parallel. So they need a version control system like Git to make sure that there are no code conflicts between them.

现实生活中的项目通常有多个开发人员并行工作。 因此,他们需要像Git这样的版本控制系统来确保它们之间没有代码冲突。

Also, the requirements in such projects change often. So a version control system allows developers to revert and go back to an older version of their code.

而且,此类项目中的要求经常更改。 因此,版本控制系统允许开发人员还原并返回其代码的旧版本。

The branch system in Git allows developers to work individually on a task (For example: One branch -> One task OR One branch -> One developer). Basically think of Git as a small software application that controls your code base, if you’re a developer.

Git中的分支系统允许开发人员单独处理一项任务(例如:一个分支->一个任务或一个分支->一个开发人员)。 如果您是开发人员,基本上可以将Git视为控制代码库的小型软件应用程序。

Git存储库 (Git Repositories)

If we want to start using Git, we need to know where to host our repositories.

如果我们想开始使用Git,我们需要知道在哪里托管我们的存储库。

A repository (or “Repo” for short) is a project that contains multiple files. In our case a repository will contain code-based files.

存储库(或简称为“ Repo”)是一个包含多个文件的项目。 在我们的情况下,存储库将包含基于代码的文件。

There are two ways you can host your repositories. One is online (on the cloud) and the second is offline (self-installed on your server).

您可以通过两种方式托管存储库。 一个在线(在云上),第二个离线(在服务器上自行安装)。

There are three popular Git hosting services: GitHub (owned by Microsoft), GitLab (owned by GitLab) and BitBucket. We’ll use GitHub as our hosting service.

有三种流行的Git托管服务:GitHub(由Microsoft拥有),GitLab(由GitLab拥有)和BitBucket。 我们将使用GitHub作为托管服务。

在使用Git之前,我们应该知道为什么需要它 (Before using Git we should know why we need it)

Git使为开源项目做出贡献变得容易 (Git makes it easy to contribute to open source projects)

Nearly every open-source project uses GitHub to manage their projects. Using GitHub is free if your project is open source, and it includes a wiki and issue tracker that makes it easy to include more in-depth documentation and get feedback about your project.

几乎每个开源项目都使用GitHub来管理他们的项目。 如果您的项目是开源的,则可以免费使用GitHub,并且其中包含Wiki和问题跟踪器,可轻松添加更深入的文档并获得有关项目的反馈。

If you want to contribute, you just fork (get a copy of) a project, make your changes, and then send the project a pull request using GitHub's web interface. This pull request is your way of telling the project you're ready for them to review your changes.

如果您想做出贡献,您只需派生一个项目(获取副本),进行更改,然后使用GitHub的Web界面向该项目发送拉取请求。 拉取请求是您告诉项目您准备好让他们检查更改的方式。

文献资料 (Documentation)

By using GitHub, you make it easier to get excellent documentation. Their help section and guides have articles for nearly any topic related to Git that you can think of.

通过使用GitHub,您可以更轻松地获取出色的文档。 他们的帮助部分和指南几乎涵盖了您可能想到的与Git相关的所有主题的文章。

整合选项 (Integration options)

GitHub can integrate with common platforms such as Amazon and Google Cloud, with services such as Code Climate to track your feedback, and can highlight syntax in over 200 different programming languages.

GitHub可以与Amazon和Google Cloud等常见平台集成,并提供Code Climate等服务来跟踪您的反馈,并可以突出显示200多种不同编程语言中的语法。

跨版本跟踪代码中的更改 (Track changes in your code across versions)

When multiple people collaborate on a project, it’s hard to keep track of revisions — who changed what, when, and where those files are stored.

当多个人在一个项目上进行协作时,很难跟踪修订-谁更改了这些文件的存储时间,存储位置和存储位置。

GitHub takes care of this problem by keeping track of all the changes that have been pushed to the repository.

GitHub通过跟踪已推送到存储库的所有更改来解决此问题。

Much like using Microsoft Word or Google Drive, you can have a version history of your code so that previous versions are not lost with every iteration. It’s easy to come back to the previous version and contribute your work.

就像使用Microsoft Word或Google云端硬盘一样,您可以拥有代码的版本历史记录,这样以前的版本就不会在每次迭代中丢失。 很容易回到以前的版本并贡献您的工作。

展示你的作品 (Showcase your work)

Are you a developer who wishes to attract recruiters? GitHub is the best tool you can rely on for this.

您是想吸引招聘人员的开发人员吗? GitHub是您可以依靠的最佳工具。

Today, when searching for new recruits for their projects, most companies look at GitHub profiles. If your profile is available, you will have a higher chance of being recruited even if you are not from a great university or college.

今天,大多数公司在为其项目寻找新兵时,大多数公司都会查看GitHub个人资料。 如果您的个人资料可用,即使您不是来自一所大学或学院,也很可能会被录用。

现在我们将学习如何使用Git和GitHub (Now we’ll learn how to use Git & GitHub)

GitHub帐户创建 (GitHub account creation)

To create your account, you need to go to GitHub's website and fill out the registration form.

要创建您的帐户,您需要访问GitHub的网站并填写注册表格。

Git安装 (Git installation)

Now we need to install Git's tools on our computer. We’ll use CLI to communicate with GitHub.

现在我们需要在计算机上安装Git工具。 我们将使用CLI与GitHub通信。

For Ubuntu:

对于Ubuntu:

  1. First, update your packages.首先,更新您的软件包。
sudo apt update

2. Next, install Git and GitHub with apt-get

2.接下来,使用apt-get安装Git和GitHub

sudo apt-get install git

3. Finally, verify that Git is installed correctly

3.最后,确认已正确安装Git。

git --version

4. Run the following commands with your information to set a default username and email when you’re going to save your work.

4.在保存您的工作时,运行以下命令并提供您的信息以设置默认用户名和电子邮件。

git config --global user.name "MV Thanoshan"
git config --global user.email "example@mail.com"

使用GitHub项目 (Working with GitHub projects)

We’ll work with GitHub projects in two ways.

我们将以两种方式处理GitHub项目。

类型1:创建存储库,将其克隆到您的PC上,然后在其上工作。(推荐) (Type 1: Create the repository, clone it to your PC, and work on it.(Recommended))

Type 1 involves creating a totally fresh repository on GitHub, cloning it to our computer, working on our project, and pushing it back.

类型1涉及在GitHub上创建一个全新的存储库,将其克隆到我们的计算机上,处理我们的项目,然后将其推回。

Create a new repository by clicking the “new repository” button on the GitHub web page.

通过单击GitHub网页上的“新存储库”按钮创建一个新存储库。

Pick a name for your first repository, add a small description, check the ‘Initialize this repository with a README’ box, and click on the “Create repository” button.

为第一个存储库选择一个名称,添加一个简短描述,选中“使用自述文件初始化该存储库”框,然后单击“创建存储库”按钮。

Well done! Your first GitHub repository is created.

做得好! 您的第一个GitHub存储库已创建。

Your first mission is to get a copy of the repository on your computer. To do that, you need to “clone” the repository on your computer.

您的首要任务是在计算机上获取存储库的副本。 为此,您需要“克隆”计算机上的存储库。

To clone a repository means that you're taking a repository that’s on the server and cloning it to your computer – just like downloading it. On the repository page, you need to get the “HTTPS” address.

克隆存储库意味着您要使用服务器上的存储库并将其克隆到计算机上,就像下载它一样。 在存储库页面上,您需要获取“ HTTPS”地址。

Once you have the address of the repository, you need to use your terminal. Use the following command on your terminal. When you’re ready you can enter this:

一旦有了存储库的地址,就需要使用终端。 在终端上使用以下命令。 准备好后,您可以输入以下内容:

git clone [HTTPS ADDRESS]

This command will make a local copy of the repository hosted at the given address.

此命令将在给定地址托管的存储库的本地副本。

Now, your repository is on your computer. You need to move in it with the following command.

现在,您的存储库在您的计算机上。 您需要使用以下命令移动它。

cd [NAME OF REPOSITORY]

As you can see in the above picture, my repository name is “My-GitHub-Project” and this command made me go to that specific directory.

如上图所示,我的存储库名称为“ My-GitHub-Project”,此命令使我进入了该特定目录。

NOTE: When you clone, Git will create a repository on your computer. If you want, you can access your project with the computer user interface instead using the above ‘cd’ command on the terminal.

注意: 克隆时,Git将在计算机上创建一个存储库。 如果需要,可以使用计算机用户界面访问项目,而不是在终端上使用上面的“ cd”命令。

Now, in that folder we can create files, work on them, and save them locally. To save them in a remote place — like GitHub – we have do a process called a “commit”. To do this, get back to your terminal. If you closed it, like I previously stated, use the ‘cd’ command.

现在,在该文件夹中,我们可以创建文件,对其进行处理并将其保存在本地。 为了将它们保存在诸如GitHub之类的远程位置,我们执行了一个称为“提交”的过程。 为此,请返回您的终端。 如果关闭它,如我之前所述,请使用“ cd”命令。

cd [NAME OF REPOSITORY]

Now, in the terminal, you’re in your repository directory. There are 4 steps in a commit: ‘status’ , ‘add’ , ‘commit’ and ‘push’. All the following steps must be performed within your project. Let's go through them one by one.

现在,在终端中,您位于存储库目录中。 提交有四个步骤:'status','add','commit'和'push'。 以下所有步骤必须在您的项目中执行。 让我们一一介绍。

  1. “status”: The first thing you need to do is to check the files you have modified. To do this, you can type the following command to make a list of changes appear.“状态”:您需要做的第一件事是检查您已修改的文件。 为此,您可以键入以下命令以显示更改列表。
git status

2. “add”: With the help of the change list, you can add all files you want to upload with the following command,

2.“添加”:在更改列表的帮助下,您可以使用以下命令添加要上传的所有文件,

git add [FILENAME] [FILENAME] [...]

In our case, we’ll add a simple HTML file.

在本例中,我们将添加一个简单HTML文件。

git add sample.html

3. “commit”: Now that we have added the files of our choice, we need to write a message to explain what we have done. This message may be useful later if we want to check the change history. Here is an example of what we can put in our case.

3.“提交”:现在我们已经添加了选择的文件,我们需要编写一条消息来解释我们所做的事情。 如果我们要检查更改历史记录,此消息可能在以后有用。 这是我们可以放入案例中的一个示例。

git commit -m "Added sample HTML file that contain basic syntax"

4. “push”: Now we can put our work on GitHub. To do that we have to ‘push’ our files to Remote. Remote is a duplicate instance of our repository that lives somewhere else on a remote server. To do this, we must know the remote’s name (Mostly remote is named origin). To figure out that name, type the following command.

4.“推送”:现在我们可以将工作放到GitHub上。 为此,我们必须将文件“推送”到远程。 远程是我们存储库的重复实例,该实例位于远程服务器上的其他位置。 为此,我们必须知道遥控器的名称(大多数遥控器称为origin)。 要找出该名称,请键入以下命令。

git remote

As you can see in the above image, it says that our remote’s name is origin. Now we can safely ‘push’ our work by the following command.

如您在上图中所看到的,它说我们的遥控器的名称是起源。 现在,我们可以通过以下命令安全地“推送”我们的工作。

git push origin master

Now, if we go to our repository on the GitHub web page, we can see the sample.html file that we’ve pushed to remote — GitHub!

现在,如果我们转到GitHub网页上的存储库,我们可以看到已推送到远程GitHub的sample.html文件!

NOTE: Sometimes when you’re using Git commands in the terminal, it can lead you to the VIM text editor (a CLI based text-editor). So to get rid of it, you have to type

注意 :有时,当您在终端中使用Git命令时,它会带您到VIM文本编辑器(基于CLI的文本编辑器)。 因此,要摆脱它,您必须输入

:q

and ENTER.

和ENTER。

Pulling is the act of receiving from GitHub.

拉动是从GitHub接收的行为。

Pushing is the act of sending to GitHub.

推送是发送到GitHub的行为。

类型2:在本地处理项目,然后在GitHub上创建存储库并将其推送到远程。 (Type 2: Work on your project locally then create the repository on GitHub and push it to remote.)

Type 2 lets you make a fresh repository from an existing folder on our computer and send that to GitHub. In a lot of cases you might have actually already made something on your computer that you want to suddenly turn into a repository on GitHub.

Type 2允许您从我们计算机上的现有文件夹中创建一个新的存储库,并将其发送到GitHub。 在很多情况下,您实际上已经在计算机上做了一些想突然变成GitHub上存储库的内容。

I will explain this to you with a Survey form web project that I made earlier that wasn’t added to GitHub.

我将通过我之前创建的Survey表单Web项目向您解释这一点,该项目并未添加到GitHub。

As I already mentioned, when executing any Git commands, we have to make sure that we are in the correct directory in the terminal.

正如我已经提到的,在执行任何Git命令时,我们必须确保我们位于终端的正确目录中。

By default, any directory on our computer is not a Git repository – but we can turn it into a Git repository by executing the following command in the terminal.

默认情况下,我们计算机上的任何目录都不是Git存储库-但我们可以通过在终端中执行以下命令将其转换为Git存储库。

git init

After converting our directory to a Git repository, the first thing we need to do is to check the files we have by using the following command.

将目录转换为Git存储库后,我们要做的第一件事是使用以下命令检查我们拥有的文件。

git status

So there are two files in that directory that we need to “add” to our Repo.

因此,该目录中有两个文件需要我们“添加”到我们的仓库中。

git add [FILENAME] [FILENAME] [...]

NOTE: To “add” all of the files in our Repository we can use the following command:

注意 :要“添加”我们存储库中的所有文件,我们可以使用以下命令:

git add .

After the staging area (the add process) is complete, we can check whether the files are successfully added or not by executing the git status

暂存区(添加过程)完成后,我们可以通过执行git status来检查文件是否成功添加

If those particular files are in green like the below picture, you’ve done your work!

如果这些特殊文件如下面的图片一样显示为绿色,则说明您已经完成工作!

Then we have to “commit” with a description in it.

然后,我们必须“提交”其中的描述。

git commit -m "Adding web Survey form"

If my repository started on GitHub and I brought it down to my computer, a remote is already going to be attached to it (Type 1). But if I’m starting my repository on my computer, it doesn’t have a remote associated with it, so I need to add that remote (Type 2).

如果我的存储库是从GitHub启动的,并且将它带到我的计算机上,则已经有一个远程附件(类型1)。 但是,如果要在计算机上启动存储库,则该存储库没有与之关联的遥控器,因此我需要添加该遥控器(类型2)。

So to add that remote, we have to go to GitHub first. Create a new repository and name it whatever you want to store it in GitHub. Then click the “Create repository” button.

因此,要添加该远程服务器,我们必须首先转到GitHub。 创建一个新的存储库,并命名为您想在GitHub中存储的任何名称。 然后单击“创建存储库”按钮。

NOTE: In Type 2, Please don’t initialize the repository with a README file when creating a new repository on the GitHub web page.

注意 :在类型2中,在GitHub网页上创建新存储库时,请不要使用README文件初始化存储库。

After clicking the “Create repository” button you’ll find the below image as a web page.

单击“创建存储库”按钮后,您将找到以下图像作为网页。

Copy the HTTPS address. Now we’ll create the remote for our repository.

复制HTTPS地址。 现在,我们将为我们的存储库创建远程。

git remote add origin [HTTPS ADDRESS]

After executing this command, we can check whether we have successfully added the remote or not by the following command

执行完此命令后,我们可以通过以下命令检查是否成功添加了遥控器

git remote

And if it outputs “origin” you’ve added the remote to your project.

并且,如果输出“ origin”,则说明已将远程添加到项目中。

NOTE: Just remember we can state any name for the remote by changing the name “origin”. For example:

注意 :请记住,我们可以通过更改名称“ origin”来声明遥控器的任何名称。 例如:

git remote add [REMOTE NAME] [HTTPS ADDRESS]

Now, we can push our project to GitHub without any problems!

现在,我们可以毫无问题地将项目推送到GitHub!

git push origin master

After completing these steps one by one, if you go to GitHub you can find your repository with the files!

在一步一步完成这些步骤之后,如果您转到GitHub,则可以找到包含文件的存储库!

结论 (Conclusion)

Thank you everyone for reading. I just explained the basics of Git and GitHub. I strongly encourage you all to read more related articles on Git and GitHub. I hope this article helped you.

谢谢大家阅读。 我只是解释了Git和GitHub的基础。 我强烈建议大家阅读有关Git和GitHub的更多相关文章。 希望本文对您有所帮助。

Check out my original article in Medium.

查看我在Medium中的原始文章。

Thank you.

谢谢。

Happy Coding!

编码愉快!

翻译自: https://www.freecodecamp.org/news/the-beginners-guide-to-git-github/

github 和git

github 和git_Git和GitHub入门指南相关推荐

  1. github 删除分支_Github新手入门指南

    这篇文章是我入门Github时期记录的笔记,当时主要是参考GitHub入门与实践 (豆瓣)一书,文中有部分内容也来源于此. 个人感觉比较适合新手入门的,感兴趣的朋友可以自行阅读. 前面的简介和Gith ...

  2. Github免费中文书《Go入门指南》,带你从零学Go | 极客头条

    点击上方↑↑↑蓝字关注我们~ 「2019 Python开发者日」全日程揭晓,请扫码咨询 ↑↑↑ 作者 | 无闻 整理 | Jane 出品 | AI科技大本营(ID:rgznai100) [导语]Go( ...

  3. GitHub Top 45:新手入门 Python,值得推荐的优质资源!

    公众号关注 "GitHubDaily" 设为 "星标",每天带你逛 GitHub! 图片来源:edureka.co 翻译 | 林椿眄 编辑 | Donna [导 ...

  4. 【Mood 16 】史上最全github使用方法:github入门到精通

    [初识Github] 首先让我们大家一起喊一句"Hello Github".YEAH!就是这样. Git 是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作L ...

  5. 快速入门github网站,了解GitHub网站的基本使用

    快速入门github网站,了解GitHub网站的基本使用 一.首先在百度输入GitHub,然后会搜索到有很多关于GitHub的链接,我们找到标题后面有官网的这个标题(带官网就是指定的官方网站),点击进 ...

  6. 《安富莱嵌入式周报》第293期:SEGGER开源其C/C++库源码emRun,丰富EMC电磁兼容资,OTA开源组件,2022 Github全球报告,内存安全指南

    往期周报汇总地址:嵌入式周报 - uCOS & uCGUI & emWin & embOS & TouchGFX & ThreadX - 硬汉嵌入式论坛 - P ...

  7. 【Github教程】史上最全github使用方法:github入门到精通(转自eoeandroid.com)

    本文来源:http://www.eoeandroid.com/thread-274556-1-1.html 另附经典教程网址 :http://wuyuans.com/2012/05/github-si ...

  8. 【Github】github是什么?github入门

    Github解释:gitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格式进行托管,故名gitHub. 注:本文章仅帮助读者入门github 正文: 掌握github ...

  9. Github教程】史上最全github使用方法:github入门到精通

    [Github教程]史上最全github使用方法:github入门到精通 [初识Github] 首先让我们大家一起喊一句"Hello Github".YEAH!就是这样. Git是 ...

最新文章

  1. GPB编辑部招聘启事 2019 Impact Factor破7;CiteScore破10
  2. 用Xamarin.Forms创建移动应用程序
  3. 如何用课件制作工具演示面积一定的矩形
  4. MyBatis-学习笔记01【01.Mybatis课程介绍及环境搭建】
  5. vue process.env获取不到_从文档开始,重学vue(下)源码级别
  6. 几行代码构建全功能对象检测模型,这位杜克大学学生做到了!
  7. 用七牛生成音乐外链方法
  8. html速成项目,HTML速成教材.doc
  9. 漏斗模型-数据分析师的必备神器
  10. 10公斤无人机动力测试台测试-拉力、扭矩、转速
  11. 【愚公系列】华为云系列之DevCloud+ECS+MySQL搭建超级冷笑话网站【开发者专属集市】
  12. 分享一个不知道从哪里下载的电子设计者的经验
  13. Cross Stage Partial Network(CSPNet)
  14. MariaDB数据库部署
  15. linux-ARM开发板--嵌入式开发平台-选型
  16. ないで与なくて的异同
  17. SpringBoot之:SpringBoot的HATEOAS基础
  18. Excel为某一列增加数据筛选
  19. 使用.NET Reflector单步调试编译好的程序集
  20. 处女...处女...

热门文章

  1. 城市公交站点及换乘方案设计
  2. 写一个矩阵相乘的函数
  3. 机器学习(1)——安装与配置 Anconda 、tensorflow、keras、jupyter notebook
  4. 优维低代码:Pipes 管道
  5. AMR NB格式解析
  6. React 报错 Too many re-renders. React limits the number of renders to prevent an infini
  7. 关于指针所占的字节数
  8. DLink624+A拨号失败的问题
  9. 网站流量有什么作用?可以刷流量吗?
  10. Nuki智能锁安全性分析