Git uses GitHub to build a remote warehouse


Introduction to this section:

In the previous section, we learned how to use Git to build our local warehouse and easily implement version control, code restoration, and modification logs Viewing, etc.; readers are definitely not satisfied with local, right? What if multiple people develop a program together? We need a remote repository as a server! Of course, setting up a server costs money, so why not host the project on Github? As an open source code base and version control system, Github has more than 1.4 million developer users. As more and more applications move to the cloud, Github has become the go-to way to manage software development and discover existing code at no cost, so why not use it? right! In this section, we will learn how to host our code on Github!

1. Account registration & warehouse creation:

Open the Github official website to register: Github official website, fill in the registration related information: user name, email, password

After registration, jump to the following page and select the warehouse purchase method (private warehouse, others cannot access, permission is required). Generally, we choose Free when playing by ourselves: PS: By the way, you may receive a verification email in your mailbox at this time, click to complete the verification.

Next, create a code repository for us:

Add some content to your repository Tip, it is some overview of the project (you can write it or not)

Briefly introduce some things on the homepage:


2. Clone the code base locally

Of course, you can clone directly using the graphical interface, but I still prefer to clone through the command line. First copy the Clone address

Then somewhere, there is a key to open Git Bash:

Type:

git clone https ://github.com/ZPJay/Garbage.git

Then you can see that our code library has been downloaded:

Open the folder and you can see the following content:


3. Branch management

For those who are new to version control tools, branches may be unfamiliar, but they will bring us great convenience. ! Due to space limitations, The author directly drops a link, and everyone will know by looking at the picture: Cao Xuefeng’s official website: Create and merge branches! The writing is really great ~ I recommend collecting it!

After understanding the concept, let’s get familiar with several commands related to branches:

①Create a branch (the latter will switch branches at the same time):

git branch v1.0.3 or git checkout -b v1.0.4

##②View the repository All branches:

git branch -a

③Switch to a certain branch:

git checkout v1.0.3

## ④Delete a branch:

git branch -D v1.0.4
⑤Merge branch

git merge v1.0.3

4. Synchronization issues between local warehouse and remote warehouse

The branch operations performed previously are all performed locally. When it comes to hosting the project on GitHub, we are sure You need to communicate with the remote warehouse, right? We already tried using the clone command to download the project locally last year. So how do we synchronize the code to Github after we modify it? We first make a little modification to our local warehouse, then prepare git add and git commit locally, and then:

git push origin master or directly git push

Submit our local content:

# Then look at our Github, you can see that the content has changed, and the submitter is another account of mine !

If it is synchronized to the server, it must be synchronized to the local server, right? It’s very simple, just a

git pull


5. Summary of this section

Okay, that’s all for this section. I believe you saw that the above Git tutorial also has some conflict resolution, branch management, Bug branch waiting for advanced Git usage, considering This is an introductory tutorial, so I won’t go into depth. If you are interested, you can learn more about it yourself. Let’s talk about the current situation of your company: ① Use Github as our project management tool: We all host the project on Github, and then have two branches: development and testing branches, one branch for each version, and the branches are merged into master when it is finally released. ! Bug reports are also mentioned above, which is quite convenient! ② Using Trello for process control is also relatively simple and efficient! Those who are interested can learn more! In addition, domestic access to Github may be slow, and if it is a private warehouse, there is a fee. If the company does not use an agent or develops privately, it may be a bit useless, but you can consider using a domestic open source warehouse: Git@OSC, developed by Open Source China provides 1,000 private warehouses. It seems to be pretty good. Those who are interested can consider hosting the code here: http://git.oschina.net/! That’s it. If there are any errors or omissions in the article, please point them out. Thank you~