mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
commit
665f9d5666
@ -1,134 +0,0 @@
|
||||
# translated by cyleft
|
||||
# translated by cyleft
|
||||
# translated by cyleft
|
||||
|
||||
A step-by-step guide to Git
|
||||
======
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/lightbulb-idea-think-yearbook-lead.png?itok=5ZpCm0Jh)
|
||||
|
||||
If you've never used [Git][1], you may be nervous about it. There's nothing to worry about--just follow along with this step-by-step getting-started guide, and you will soon have a new Git repository hosted on [GitHub][2].
|
||||
|
||||
Before we dive in, let's clear up a common misconception: Git isn't the same thing as GitHub. Git is a version-control system (i.e., a piece of software) that helps you keep track of your computer programs and files and the changes that are made to them over time. It also allows you to collaborate with your peers on a program, code, or file. GitHub and similar services (including GitLab and BitBucket) are websites that host a Git server program to hold your code.
|
||||
|
||||
### Step 1: Create a GitHub account
|
||||
|
||||
The easiest way to get started is to create an account on [GitHub.com][3] (it's free).
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide1.png)
|
||||
|
||||
Pick a username (e.g., octocat123), enter your email address and a password, and click **Sign up for GitHub**. Once you are in, it will look something like this:
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide2.png)
|
||||
|
||||
### Step 2: Create a new repository
|
||||
|
||||
A repository is like a place or a container where something is stored; in this case we're creating a Git repository to store code. To create a new repository, select **New Repository** from the `+` sign dropdown menu (you can see I've selected it in the upper-right corner in the image above).
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide3.png)
|
||||
|
||||
Enter a name for your repository (e.g, "Demo") and click **Create Repository**. Don't worry about changing any other options on this page.
|
||||
|
||||
Congratulations! You have set up your first repo on GitHub.com.
|
||||
|
||||
### Step 3: Create a file
|
||||
|
||||
Once your repo is created, it will look like this:
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide4.png)
|
||||
|
||||
Don't panic, it's simpler than it looks. Stay with me. Look at the section that starts "...or create a new repository on the command line," and ignore the rest for now.
|
||||
|
||||
Open the Terminal program on your computer.
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide5.png)
|
||||
|
||||
Type `git` and hit **Enter**. If it says command `bash: git: command not found`, then [install Git][4] with the command for your Linux operating system or distribution. Check the installation by typing `git` and hitting **Enter** ; if it's installed, you should see a bunch of information about how you can use the command.
|
||||
|
||||
In the terminal, type:
|
||||
```
|
||||
mkdir Demo
|
||||
```
|
||||
|
||||
This command will create a directory (or folder) named Demo.
|
||||
|
||||
Change your terminal to the Demo directory with the command:
|
||||
```
|
||||
cd Demo
|
||||
```
|
||||
|
||||
Then enter:
|
||||
```
|
||||
echo "#Demo" >> README.md
|
||||
```
|
||||
|
||||
This creates a file named `README.md` and writes `#Demo` in it. To check that the file was created successfully, enter:
|
||||
```
|
||||
cat README.md
|
||||
```
|
||||
|
||||
This will show you what is inside the `README.md` file, if the file was created correctly. Your terminal will look like this:
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide7.png)
|
||||
|
||||
To tell your computer that Demo is a directory managed by the Git program, enter:
|
||||
```
|
||||
git init
|
||||
```
|
||||
|
||||
Then, to tell the Git program you care about this file and want to track any changes from this point forward, enter:
|
||||
```
|
||||
git add README.md
|
||||
```
|
||||
|
||||
### Step 4: Make a commit
|
||||
|
||||
So far you've created a file and told Git about it, and now it's time to create a commit. Commit can be thought of as a milestone. Every time you accomplish some work, you can write a Git commit to store that version of your file, so you can go back later and see what it looked like at that point in time. Whenever you make a change to your file, you create a new version of that file, different from the previous one.
|
||||
|
||||
To make a commit, enter:
|
||||
```
|
||||
git commit -m "first commit"
|
||||
```
|
||||
|
||||
That's it! You just created a Git commit and included a message that says first commit. You must always write a message in commit; it not only helps you identify a commit, but it also enables you to understand what you did with the file at that point. So tomorrow, if you add a new piece of code in your file, you can write a commit message that says, Added new code, and when you come back in a month to look at your commit history or Git log (the list of commits), you will know what you changed in the files.
|
||||
|
||||
### Step 5: Connect your GitHub repo with your computer
|
||||
|
||||
Now, it's time to connect your computer to GitHub with the command:
|
||||
```
|
||||
git remote add origin https://github.com/<your_username>/Demo.git
|
||||
```
|
||||
|
||||
Let's look at this command step by step. We are telling Git to add a `remote` called `origin` with the address `https://github.com/<your_username>/Demo.git` (i.e., the URL of your Git repo on GitHub.com). This allows you to interact with your Git repository on GitHub.com by typing `origin` instead of the full URL and Git will know where to send your code. Why `origin`? Well, you can name it anything else if you'd like.
|
||||
|
||||
Now we have connected our local copy of the Demo repository to its remote counterpart on GitHub.com. Your terminal looks like this:
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide8.png)
|
||||
|
||||
Now that we have added the remote, we can push our code (i.e., upload our `README.md` file) to GitHub.com.
|
||||
|
||||
Once you are done, your terminal will look like this:
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide9.png)
|
||||
|
||||
And if you go to `https://github.com/<your_username>/Demo` you will see something like this:
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide10.png)
|
||||
|
||||
That's it! You have created your first GitHub repo, connected it to your computer, and pushed (or uploaded) a file from your computer to your repository called Demo on GitHub.com. Next time, I will write about Git cloning (downloading your code from GitHub to your computer), adding new files, modifying existing files, and pushing (uploading) files to GitHub.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/1/step-step-guide-git
|
||||
|
||||
作者:[Kedar Vijay Kulkarni][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/kkulkarn
|
||||
[1]:https://opensource.com/resources/what-is-git
|
||||
[2]:https://opensource.com/life/15/11/short-introduction-github
|
||||
[3]:https://github.com/
|
||||
[4]:https://www.linuxbabe.com/linux-server/install-git-verion-control-on-linux-debianubuntufedoraarchlinux#crt-2
|
128
translated/tech/20180125 A step-by-step guide to Git.md
Normal file
128
translated/tech/20180125 A step-by-step guide to Git.md
Normal file
@ -0,0 +1,128 @@
|
||||
手把手指导您使用 Git
|
||||
======
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/lightbulb-idea-think-yearbook-lead.png?itok=5ZpCm0Jh)
|
||||
|
||||
如果您从未使用过 [Git][1],甚至可能从未听说过它。莫慌张,只需要一步步地跟着入门教程,很快您就会在 [GitHub][2] 上拥有一个全新的 Git 仓库。
|
||||
|
||||
在开始之前,让我们先理清一个常见的误解:Git 并不是 GitHub。Git 是一套版本控制系统(或者说是一款软件),能够协助您跟踪计算机程序和文件在任何时间的更改。它同样允许您在程序、代码和文件操作上与同事协作。GitHub 以及类似服务(包括 GitLab 和 BitBucket)都属于部署了 Git 程序的网站,能够托管您的代码。
|
||||
|
||||
### 步骤 1:申请一个 GitHub 账户
|
||||
|
||||
在 [GitHub.com][3] (免费)网站上创建一个账户是最简单的方式。
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide1.png)
|
||||
|
||||
选择一个用户名(比如说,octocat123),输入您的邮箱地址和密码,然后点击 **Sign up for GitHub**。进入之后,您将看到下方插图的界面:
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide2.png)
|
||||
|
||||
### 步骤 2:创建一个新的 repository
|
||||
|
||||
一个 repository(仓库),类似于能储存物品的场所或是容器;在这里,我们创建仓库存储代码。在 `+` 符号内(在插图的右上角,我已经选中它了) 的下拉菜单中选择 **New Pepositiry**。
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide3.png)
|
||||
|
||||
给您的仓库命名(比如说,123)然后点击 **Create Repository**。无需考虑本页面的其他选项。
|
||||
|
||||
恭喜!您已经在 GitHub.com 中建立了您的第一个仓库。
|
||||
|
||||
### 步骤 3: 创建文件
|
||||
|
||||
当仓库创建完毕后,界面将和下方一致:
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide4.png)
|
||||
|
||||
不必惊慌,它比看上去简单。跟紧步骤。忽略其他内容,注意截图上的“...or create a new repository on the command line,”。
|
||||
|
||||
在您的计算机中打开终端。
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide5.png)
|
||||
|
||||
键入 `git` 然后回车。如果命令行显示 `bash: git: command not found`,在您的操作系统或发行版使用 [安装 Git][4] 命令。键入 `git` 并回车检查是否成功安装;如果安装成功,您将看见大量关于使用说明的信息。
|
||||
|
||||
在终端内输入:
|
||||
```
|
||||
mkdir Demo
|
||||
```
|
||||
这个命令将会创建一个名为 Demo 的目录(文件夹)。
|
||||
|
||||
如下命令将会切换终端目录,跳转到 Demo 目录:
|
||||
```
|
||||
cd Demo
|
||||
```
|
||||
|
||||
然后输入:
|
||||
```
|
||||
echo "#Demo" >> README.md
|
||||
```
|
||||
创建一个名为 `README.md` 的文件,并写入 `#Demo`。检查文件是否创建成功,请输入:
|
||||
|
||||
```
|
||||
cat README.md
|
||||
```
|
||||
这将会为您显示 `README.md` 文件的内容,如果文件创建成功,您的终端会有如下显示:
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide7.png)
|
||||
|
||||
使用 Git 程序告诉您的电脑,Demo 是一个被 Git 托管的目录,请输入:
|
||||
```
|
||||
git init
|
||||
```
|
||||
|
||||
然后,告诉 Git 程序您关心的文件并且想在此刻起跟踪它的任何改变,请输入:
|
||||
```
|
||||
git add README.md
|
||||
```
|
||||
|
||||
### 步骤 4:创建一次提交
|
||||
|
||||
目前为止,您已经创建了一个文件,并且已经通知了 Git,现在,是时候创建一次提交了。提交被看作为一个里程碑。每当完成一些工作之时,您都可以创建一次提交,保存文件当前版本,这样一来,您可以返回之前的版本,并且查看那时候的文件内容。无论那一次,您对修改过后的文件创建的新的存档,都和上一次的不一样。
|
||||
|
||||
创建一次提交,请输入:
|
||||
```
|
||||
git commit -m "first commit"
|
||||
```
|
||||
|
||||
就是这样!刚才您创建了包含一条注释为“first commit”的 Git 提交。每次提交,您都必须编辑注释信息;它不仅能协助您识别提交,而且能让您理解此时您对文件做了什么修改。这样到了明天,如果您在文件中添加新的代码,您可以写一句提交信息:添加了新的代码,然后当您一个月后回来查看提交记录或者 Git 日志(提交列表),您还能知道当时的您在文件夹里做了什么。
|
||||
|
||||
### 步骤 5: 将您的计算机连接到 GitHub 仓库
|
||||
|
||||
现在,是时候用如下命令将您的计算机连接到 GitHub 仓库了:
|
||||
```
|
||||
git remote add origin https://github.com/<your_username>/Demo.git
|
||||
```
|
||||
|
||||
让我们一步步的分析这行命令。我们通知 Git 去添加一个叫做 `origin` 的,拥有地址为 `https://github.com/<your_username>/Demo.git`(它也是您的 GitHub 地址仓库) 的 `remote`。当您递送代码时,允许您在 GitHub.com 和 Git 仓库交互时使用 `origin` 而不是完整的 Git 地址。为什么叫做 `origin`?当然,您可以叫点别的,只要您喜欢。
|
||||
|
||||
现在,在 GitHub.com 我们已经连接并复制本地 Demo 仓库副本到远程仓库。您的设备会有如下显示:
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide8.png)
|
||||
|
||||
此刻我们已经连接到远程仓库,可以推送我们的代码(上传 `README.md` 文件) 到 GitHub.com。
|
||||
|
||||
执行完毕后,您的终端会显示如下信息:
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide9.png)
|
||||
|
||||
然后,如果您访问 `https://github.com/<your_username>/Demo`,您会看到截图内显示的情况:
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/git_guide10.png)
|
||||
|
||||
就是这么回事!您已经创建了您的第一个 GitHub 仓库,连接到了您的电脑,并且在 GitHub.com 推送(或者称:上传)名叫 Demo 的文件到您的远程仓库。下一次,我将编写关于 Git 复制、添加新文件、修改现存文件、推送(上传)文件到 GitHub。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/1/step-step-guide-git
|
||||
|
||||
作者:[Kedar Vijay Kulkarni][a]
|
||||
译者:[CYLeft](https://github.com/CYLeft)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/kkulkarn
|
||||
[1]:https://opensource.com/resources/what-is-git
|
||||
[2]:https://opensource.com/life/15/11/short-introduction-github
|
||||
[3]:https://github.com/
|
||||
[4]:https://www.linuxbabe.com/linux-server/install-git-verion-control-on-linux-debianubuntufedoraarchlinux#crt-2
|
Loading…
Reference in New Issue
Block a user