An article takes you quickly to GitHub

I started on GitHub the year before last. I didn’t know where to start at the beginning. I found many articles and tutorials on the Internet. This article is written from the perspective of Xiaobai when I was just learning. I hope it can help learners who want to start learning GitHub but don't know how to get started. Because I am also at a beginner level, the knowledge introduced in the article is based on my own learning and understanding. If there are omissions and errors, please leave a message to correct me, thank you!

Novice Xiaobai may have the following confusion about GitHub:
1. What website is GitHub ?
2. Why do I hear people say I want to learn Git when I talk about learning GitHub? Is there any connection between these two? Is it the same thing?
3. I heard that GitHub is an open source community, where you can learn technology and improve code with others. How do you communicate with others?

Below, I will answer from these aspects.

1. Take you to the GitHub website and see what's there?

1. Register an account

Open the GitHub website , the home page is as shown in the figure below, click the Sign upbutton in the upper right corner to enter the registration page. Register by email, set the username and password, and then you can generate an account. After completing the registration, click the Sign inbutton beside to log in.
Registration/Login Page

2. Log in to GitHub, browse the page

After logging in, the page we see is divided into three sections, as shown in the figure below, from left to right: own repositories, dynamics of people you follow, and discover new hot/interesting repositories.
Home page example after login

Possible questions: Repository? Warehouse? Is it a bit hard to understand?
I also encountered this confusion when I was a beginner. "Repository" means "warehouse", and we can understand it as a warehouse that stores all kinds of documents needed by the project. After you are familiar with it, you will find that there are various warehouses on GitHub, not only containing program code, but also learning course documents, etc., no wonder it is called a warehouse, haha. Repository (repository) plays an important role on GitHub, and many of our future operations will be carried out in Repository (repository).

Click on the profile picture in the upper right corner and select an Your profileitem in the drop-down list to reach the profile page. The picture below shows my personal homepage.
Personal homepage example

If you open another person's homepage, the interface style you see is roughly the same. I briefly indicated the functions on the page in the figure, in addition:

  1. Click the Edit profilebutton below the account name to modify your personal information, such as a one-sentence introduction here, company, address, contact information, etc. And if it is someone else’s personal homepage, what we see here is the Follow(Follow) button.

  2. There is a star icon on the right of the number of fans and followers, this is the legendary Star. When we read technical articles, we may often encounter similar introductions such as "A must-see for programmers! A project with tens of thousands of Stars on GitHub!", "This project quickly gained thousands of Stars on GitHub". It seems that the number of Stars is very important. Logo! So, what does Star mean? For example, we think a warehouse is good. Clicking a Star in the upper right corner is equivalent to favorites + likes. You can also click the star icon on your homepage to view it later.
    Warehouse page-Star

  3. The "Pinned" area is your own personal display area. Select a few from your own warehouse and display them here, so that others can quickly discover your shining points.

  4. Activity table: The more green grids above, the darker the color, indicating that the user has submitted more times on GitHub and is an active user.

2. GitHub is the project management center for Git software users

1. Git

The reason why GitHub got this name is inseparable from Git, a distributed version control software. In layman's terms, Git software records the state of the file every time you modify it. Even better, if you change and feel that the previous version is better, you can go back, that is to say, there is a "regret medicine" to take! At the same time, Git is also an excellent collaboration software. To make a simple analogy, Xiao Hong and Xiao Lan and I am editing an article together. Everyone may make different changes, so merging the revised manuscripts is a headache. Or, should I make changes first, then make changes to Xiaohong, and finally make changes to Xiaolan? This way the efficiency is reduced. How to do? With Git, the three of us can create modified branches, make modifications at the same time, and finally merge the branches. You may ask, if the three of you make different changes in the same place, can you still merge it? Don't worry, the software considers this "conflict" situation and has a corresponding solution.

Since Git can collaborate, there must always be a place for people who use it to store files, modifications, and other information, just like a control center. In this way, GitHub came into being. One more thing here, Git's hosting center is not only GitHub, GitHub is a convenient website for individual users and open source projects. Some companies build their own servers and cloud disks to build a hosting center, and also use Git software for collaborative management.

So, how to use Git software?
(1) First go to the official Git website to download and install the Git software.
(2) After the installation is successful, select a folder and select it from the right-click menu. Git Bash HereA black command line interface will pop up. Enter the sentence and you can run Git commands in the current folder.

It is recommended to study the Git tutorial of teacher Liao Xuefeng , the explanation is clear and easy to understand, from which we can understand the various operations of Git. Then, follow the instructions of the tutorial and build a new folder by yourself to practice.

2. Git basic commands

There are still many Git commands, but for novices, we can first master a few basic Git commands commonly used on GitHub :

(1) Submit revision: git addandgit commit
Schematic diagram of git operation, picture from Git official website

The above diagram is from the official Git website and illustrates the workflow of the most important operations "git add" and "git commit" in Git. The core of Git software is to save changes. Working directory is the working area, which is the current working folder on our computer. staging area or staging area can be understood as the relay station, git add .(note: this add and .the intermediate space) submitted to modify, on temporary staging area, and then by git commit -m"修改说明文字"finally submitted version determined. Don't underestimate this buffered temporary storage area, it provides us with "regret medicine" when modifying. This effect is similar to how we usually delete files on the computer. The files will not be deleted directly, but will be transferred to the recycle bin. If we find that the hand trembling has been deleted by mistake, we can "restore" the files in the recycle bin, or if we are sure that they are not needed, click "Empty Recycle Bin" to delete all these files.

(2) Synchronize with remote warehouse: git pullandgit push

In the case of multi-person collaboration, such as the aforementioned example of me writing an article with Xiao Hong and Xiao Lan, everyone's changes may be inconsistent, so keep in sync. If we want to get updates from remote warehouses and push our own changes, we need to use git pulland git push. The aforementioned git commitis to determine the result of my own final modifications, git pushsucked this modification results are submitted to a remote repository (such as GitHub on) a (warehouse) to save. I always remember the main points mentioned in teacher Liao Xuefeng's tutorial: the first thing to start working every day is git pullto keep up with the latest revision of the project. End of the day, when you submit changes, first git pullagain git push.

(3) Download the repository (warehouse): git clone

Open a warehouse, we will see the Codebutton, after clicking, the HTTPS address and SSH address will appear below. We only need to copy this address, then right-click on the storage folder on the computer, open the Git Bash client, and enter the command line: git clone 复制的地址to download the warehouse to the local computer.
Download warehouse diagram

It should be noted that using HTTPS addresses requires account verification. To use the SSH address, you only need to submit the SSH Key to GitHub the first time, and you do not need to verify each time. It is very convenient. Next, we will introduce how to configure the SSH Key.

Note: When writing this article, I also had a confusion: I don’t know if it’s because I have already used SSH for authentication. When I used the git clone HTTPS 地址download , I did not ask for the account name and password authentication. Friends, please tell me the results of your practice, thank you!

Three, basic GitHub operations for novices

1. Configure SSH Key

(1) When using it for the first time, configure the account.

In the Git Bash client, enter:

git config --global user.name "这里输入你在GitHub的账户名"
git config --global user.email "这里输入你在GitHub的注册邮箱名"

(2) Check whether there is an SSH Key, and if not, generate one.

Also in the Git Bash client, enter:

cd ~/.ssh

with

ls

My account has generated an SSH Key, and has id_ras and id_rsa.pub as shown below. Please note that id_ras.pub is the public key, which will be uploaded to GitHub for verification later. id_rsa is your own private key, keep it well.

id_rsa  id_rsa.pub  known_hosts

If there is no SSH Key, enter the following command line to generate:

ssh-keygen -t rsa -C "这里输入你在 GitHub 的注册邮箱"

After generation, enter the above cd ~/.sshand lscommand to see the SSH Key.

(3) Copy the public key.

Then in the Git Bash client, enter the command line:

cat id_ras.pub

This will display the contents of the public key file, and we will copy it to the clipboard.

(4) Add the copied public key to the GitHub account for installation.

Log in to your GitHub account and click on the drop-down menu of your profile picture in the upper right corner, as shown in the figure:
Personal avatar menu

Click Settings> SSH and GPG Keys in turn. There is a New SSH Keybutton in the upper right corner of the SSH Keys page . After clicking the button, paste the public key content you just copied. The "title" item inside is to give your SSH Key a name, which can be whatever you like.

(5) Finally, check whether the SSH Key is successfully installed.

Run the command in the Git Bash client:

$ ssh -T [email protected]

A prompt similar to the following appears, indicating a successful installation:

Hi Juliecodestack! You've successfully authenticated, but GitHub does not provide shell access.
2. My first GitHub project: How to create a new upload warehouse

After learning so many basic skills, we finally have to practice hands, haha, let’s build our own warehouse for fun!

(1) Create a new warehouse in GitHub

As shown in the figure below, click the Repositories item of the personal homepage, and then click the Newbutton on the right to create a new warehouse.
Warehouse page-new button

I have made a simple demonstration here, as shown in the figure below, you can fill in according to my template, and finally click the Create repositorybutton at the bottom to create a new warehouse.
New warehouse filling page

Open the newly created warehouse, as shown in the figure below, the content of the Readme file of this warehouse is the warehouse name and description just filled in. We click the Codebutton and copy the SSH address.
Warehouse page-testexample2020

(2) Download the warehouse file to the computer.

Suppose we want to download to the target folder on the computer (for the convenience of description, here is referred to as folder A), then we right-click on folder A, select "Git Bash" in the right-click menu, and enter commands in the Git Bash client Row:

git clone SSH地址

In this way, the warehouse will be downloaded to folder A.

(3) Modify the warehouse file, use the Git command to submit the modification and push to GitHub.

After downloading the warehouse, we will find that there is a new subfolder in folder A. For example, I downloaded the warehouse testexample2020 in the previous step, and a new file named "testexample2020" appears in folder A. Folder, this is the warehouse downloaded to the local computer. We open this new folder ( "testexample2020"), or use VSCode Atom Editor (using the method editor can refer to my article: easy to understand tutorial Markdown ), add a line in the Readme file: hello,world!. Main.py then create a new file, enter a single line of code is: print("hello").

After the modification, we right-click on the folder testexample2020 (note: this is not Git Bash on the parent folder A), open the Git Bash client, and enter the command line in turn:

git add .

git commit -m"v0.1"

git push

This modification is pushed to the repository on GitHub.

(4) Log in to GitHub and check the changes in the warehouse.

After logging in to GitHub, we found that the changes we just made were synchronized to the GitHub repository, as indicated in the figure below:
Warehouse page-after change

3. Do projects with others: Fork and Pull request

As mentioned earlier, GitHub is an open source community. We can participate in open source projects. So, how do we do it?

Let me give an example of my own to illustrate this process.

(1) Fork a warehouse of others

When I was learning the API interface, many of the Weibo API toolkits on the Internet were written based on Python2. I found a Python3 version of sinaweibopy3 on Github , as shown in the figure below. I used it and found it very good. When I saw that the author did not write a Readme, I wanted to add a Readme document so that others could understand the functions and usage of this warehouse more quickly. In other words, I want to do this to this warehouse. Some modifications. In this case, I have to fork this warehouse to myself.
sinaweibopy3 repository page

Why fork?
Fork means "fork", which is to copy and build my own branch (fork) from the original warehouse. In this way, the changes I make are only on my own branch and will not affect the original warehouse unless I submit After the pull request is accepted.

After Fork, the same warehouse sinaweibopy3 appeared in my warehouse, as shown in the figure below. The difference is that there is a note below the warehouse name: "Forked from olwolf/sinaweibopy3".
Fork's warehouse

(2) Make changes to your Fork warehouse

Next, I modified Fork's sinaweibopy3 warehouse and added a Readme document. Details, please refer Previous: Example "2. My first GitHub project how to upload new warehouse", you can first git clonedownload to a local folder, modify it and then git pushpushed to GitHub.

(3) Submit Pull request

As shown in the figure below, click Pull request, fill in some information in the pop-up interface, tell the author of the original warehouse what changes you made, why you want to modify, etc., so that the author can understand your changes to the warehouse, and then submit, and the Pull request request will be Send to the author of the original warehouse.
Pull request example

(4) Wait for the author of the original warehouse to check and decide whether to accept the modification.

After submitting the Pull request, we wait for a while, and the author of the original warehouse will decide whether to accept the modification.

Here, olwolf, the original author of the warehouse sinaweibopy3, merged my modifications, as shown in the figure, so that the Readme file is also added to the original warehouse. At the same time, I became one of the contributors to the warehouse.
Changes to the original warehouse after accepting the Pull request

Four, summary

After completing the above learning, we are basically getting started. Next, you can explore it yourself on GitHub, such as searching and discovering some interesting projects, paying attention to some experts, adding to open source projects, and so on. Most importantly, hands-on practice! Once you get started and get familiar with it, you will find that it is not as difficult as you might have imagined. Let's go for it!

Finally, recommend a few good learning tutorials:

1. GitHub Help Page

2. Git tutorial by teacher Liao Xuefeng

3. How to configure SSH Key on GitHub

Guess you like

Origin blog.csdn.net/applebear1123/article/details/113030915