GitHub roaming Guide

Posted on

GitHub roaming Guide
GitHub is a hosting platform for open-source and private software projects. Due to the large number of users but the serious imbalance between men and women, GitHub is nicknamed as the world’s largest same-sex dating website in the program industry. At that time, Linux system came out in an unprecedented splendor. More and more program apes joined in the development and maintenance army. Such a huge project volume does not have a good project hosting platform. So Linus Daniel, the founder of Linux, spent two weeks compiling a distributed version control system in C language, that is GIT. Then git quickly became the most popular distribution In 2008, GitHub launched its version control system, which provides git storage for open source projects free of charge. Last year, it was purchased by Microsoft Dad (from the poor gaze) for $7.5 billion.

Now, Git is built in vs code. You can directly perform git operation in vs Code by configuring the file path and default opening method, which is very convenient and fast.
GitHub roaming Guide

Many of the world’s top technology companies contribute their projects to GitHub, and we can also find many excellent open source projects on it. Thanks to GitHub, we can gallop freely in an open and smooth Internet world. Now GitHub has become the face-to-face person in the process of product development. Many enterprises will require candidates to provide GitHub accounts when interviewing. An excellent GitHub account will certainly add a lot of color to your job search.

This paper briefly introduces the birth and history of GitHub, and then explains how to use it.

Here is git’s official website, covering a very comprehensive set of GIT documents:

There are many git tutorials and related books on the market. They are usually very thick. If you are a beginner, we recommend Mr. Liao Xuefeng’s git tutorials. They cover all the basic functions. They can be used quickly from simple to deep. This article is based on his tutorial, according to my own use habits, from a novice point of view to reorganize, after serious study, everyone will have different harvest, find the right one for me.

1. Install Git

First of all, you need to install git locally on your own computer. Git comes with MAC system. You need to download and install windows system. The process is very simple and convenient. I won’t elaborate here. For specific installation methods of different systems, please refer to teacher Liao Xuefeng’s blog:…

2. Sign up for GitHub account

Fill in user name, email address and password on GitHub website to register personal account.
GitHub roaming Guide

After successful registration, you will enter GitHub homepage, with navigation bar at the top and left to right at the bottom:

Warehouse:All the warehouses you create will be displayed here

Timeline:Some activities of the people you pay attention to, such as creating a new warehouse, or star, fork, etc., will be displayed here, similar to Weibo dynamics.

New warehouse found:Here we will recommend some excellent projects with high standard stars, similar to popular microblogs.

Briefly introduce the modules of the head navigation bar:
GitHub roaming Guide

LOGO:Click to enter GitHub Homepage

Search box:Search for users or items

Pull requestes:View push request information

Issues:View problem push information

Marketplace:The latest software is provided here, which is code software Mart
GitHub roaming Guide

Explore:Introducing popular software on GitHub

3. Configure GitHub account locally

After installing git, enter:

$git config — global user. Name “your GitHub user name”
$git config — global “your GitHub registered email”

To configure your own GitHub user name and email address

4. Create SSH key key

GitHub needs to confirm that the content is pushed by you through SSH protocol, otherwise anyone can submit changes to your warehouse, which is very dangerous. When using multiple computers for development, you need to configure multiple SSH keys to ensure that you can push the content to your own warehouse.

First, find the. SSH directory locally. Mac users use the shortcut key: Shift + Command + G to enter ~ /. SSH for quick search. Check whether there are two files in the directory: id_rsa (private key) and (public key). If not, run SSH keygen – t RSA – C “your GitHub mailbox” in the terminal to generate SSH key.
GitHub roaming Guide
Enter the GitHub website, click the personal portrait in the upper right corner, find settings in the bottom, find SSH and GPG keys in the sixth option on the left, click New SSH key, paste the content in your into the key, fill in any title, and save it, then you can push the content to the remote GitHub warehouse locally.
GitHub roaming Guide
GitHub roaming Guide

5. Synchronize local warehouse repository to remote

(1) Initialize a git warehouse: git init

After executing this command, there will be another. Git directory under the current directory. This directory is git to track and manage the version library. Do not delete it. If you cannot see the modification of this file, open the display hidden file.

(2) Add file to warehouse command:

Git add filename adds the specified file to the staging area, separated by spaces

Git add / git add – A / git add — all add all workspace contents to the staging area (including adding, modifying, and deleting files)

Git add. Add all contents in the current directory to the temporary storage area (including adding and modifying files)

After executing the add operation, you are right without any display. In the process of using git, remember that no message is good news, and only when there is an error, it will give you an error message.

This command can be used multiple times. Submit all the files you need to add to the staging area, and then execute git commit once to submit the files submitted to the staging area multiple times to the current branch at one time.

(3) Submit file to current branch

Git commit – M “commit instructions”

Git status view the submission status of the current workspace. Show after all submissions:

nothing to commit, working tree clean

Git diff view the modified content. The contents of the files in the staging area and the workspace are compared.

(4) Push to remote warehouse

First, create a new remote warehouse, click the plus sign in the upper right corner of GitHub homepage, select the first option new repository, fill in the repository name, description description, select the public attribute, check the initial this repository with a readme, and a readme document in markdown format will be automatically generated. In this way, we have created a git warehouse remotely. At present, it’s free to create an open warehouse on GitHub. Everyone can see the content in the warehouse. If you want to create a private warehouse for a fee, it encourages you to open source.
GitHub roaming Guide
After the warehouse is created, he gives different prompts in three situations:

Create a new warehouse locally and push content to a remote warehouse

We just need to follow the instructions as follows:

Echo “ා git test demo” > > create a new readme file and write the content

Git init generates. Git version Library

Git add submits files from the current workspace to the staging area

Git commit – M “first commit” commits the contents of the staging area to the current branch

Git remote add origin hanxueqing / git-test-demo.git associate remote library locally

Here you can choose to use HTTPS connection or SSH connection. When using HTTPS connection, password verification is required for each push. It is relatively safe, but the disadvantage is slow. If SSH connection is used, you will get a warning when you connect GitHub with git’s clone or push command for the first time:

The authenticity of host ' (xx.xx.xx.xx)' can't be established.
RSA key fingerprint is xx.xx.xx.xx.xx.
Are you sure you want to continue connecting (yes/no)?

Just enter yes

Git will output a warning that you have added GitHub’s key to a local trust list:

Warning: Permanently added '' (RSA) to the list of known hosts.

This warning will only appear once, and there will be no warning for subsequent operations.

Git push – U origin master pushes the current branch to the corresponding branch of the origin master.

Because the remote library is empty, when we push the master branch for the first time, we add the – U parameter to push the local master branch to the origin host, and specify the origin as the default host. In the later push or pull, we can simplify the command, and use git push to push without any parameters.

If there is an existing local warehouse, the desired content can be quickly pushed to the current warehouse. Only the following two instructions need to be executed:

git remote add origin

git push -u origin master

You can also import warehouses from other version control systems such as subversion, mercurial, or TFs project

Since I checked auto generate readme document when I first created a new warehouse, and this document does not exist in my local file, an error will be reported when I push to the remote warehouse, indicating:

error: failed to push some refs to ''
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

The reason is that the current version is lower than the remote warehouse version. You can first pull the remote warehouse to the local place, execute the GIT pull origin master command, and then execute the GIT push – U origin master command to push the remote warehouse.

Or create a new branch, GIT branch, and push it to the new branch, GIT push – U origin.

Here I directly use the method of forced push: git push – U origin master – F, but it will cover remote files, which is generally not recommended, especially when developing by multiple people.

After the above operations are performed locally, a successful command can be submitted to the terminal.
GitHub roaming Guide

At this point, we will enter the warehouse created before entering GitHub account and find that all the files in the workspace have been uploaded in remote synchronization.
GitHub roaming Guide
Briefly explain the functions of each module in the warehouse:
GitHub roaming Guide
Watch: it’s similar to watching. After you watch a project, you will be notified whenever there is any update to the project.

Star: similar to praise, it’s much more difficult to get standard stars on GitHub than on social networks. Generally, it’s very good to get 1000 + star projects. Recently, the 996 ICU project in the development circle has reached 245k.
GitHub roaming Guide
Fork: create a branch of the warehouse project and add it to your own warehouse. You can develop it on the basis of the original warehouse. After the function is complete, you can initiate the pull request request to merge the branch with the original warehouse and integrate the function.

Code: displays the list of files for the warehouse.

Issues: it is mainly used for bug report, function addition, directional discussion, etc., similar to the message board function of a discussion area. Bug is managed in the form of issues, which can be closed manually after being solved.

Pull request: view and manage pull requests from others.

Projects: This is a very powerful project management mode, which can better manage your issues. Some people use project + issues to write technical blogs on GitHub.

You can pay attention to:

Wiki: wiki is a simpler page description function than HTML syntax. It is often used to record information or software documents that should be shared between developers.

Security: security warning

Insights: display the activity information of the warehouse and detect the development progress

Settings: settings. You can set the current warehouse here, such as changing the warehouse name, changing the description information, and deleting the current warehouse. However, this operation is dangerous. It allows you to enter the name of the current warehouse for secondary confirmation. If there is something in the warehouse, it also allows you to enter the account and password for secondary confirmation. The security level is very high.
GitHub roaming Guide
GitHub roaming Guide
Commits: commit log

Branches: Branch Management

Releases: release management

Contributors: people involved in development

Branch: Master: switch branches and display the list of files under different branches

New pull request: initiate a merge request to the original warehouse

Create new file: create a new file

Upload files: upload files

Find files: find files

Clone or download: provide HTTPS protocol or SSH protocol for clone and download

Next, it introduces some common basic operations of GIT, which is convenient for subsequent use.


Here we have to define several concepts: workspace, staging area, current branch, remote warehouse

Workspace: a directory of files on our own computers

Staging area: the stage file in the GIT directory temporarily stores our changes to the file. Git add is to add the file to the staging area.

Current branch: git automatically creates a master branch for us. Git commit is to submit file changes to the current branch.

Remote warehouse: the repository we created at the beginning, GIT push is to push all changes to the remote warehouse.

Undo the changes in the workspace (at this time, you just modify the file, but you haven’t done any git operations): git checkout — File

Undo the modification of the staging area (at this time, you not only modify the file, but also add the modification to the staging area): git reset head < File > and then execute git checkout — File

Undo the changes submitted to the branch (at this time, you not only modify the file, but also git add adds the changes to the staging area, and git commit submits to the current branch): carry out the version fallback operation to be discussed next

Version switching

If you submit modification files to the current warehouse multiple times, you can use git log to view the complete submission log. A large number after the commit is the version number. Git implements version backoff and forward by letting the internal head pointer point to a specific version number.
GitHub roaming Guide

If you submit multiple times, there is a long list of submission logs. You don’t want to display the author and date. You only need the first row of data to run git log — pretty = online

If you think the commitid is too long and only want to keep a few significant digits, you can run git log — online — graph

Fallback command: git reset — hard commit “ID can be fallback to the specified version

Git reset — hard head ^ head refers to the current version, head is the previous version, and the previous version is head ^. If you go back to the earlier version, you can write it as head number (how many versions before you go back)

Forward command: after executing the version fallback command and executing git log, you will find that the updated version after this version is missing. Don’t panic at this time. It hasn’t been deleted or overwritten. Git provides a command: git reflog to record your every command. As long as you find the commit ID of the file you want to recover, execute git reset — hard The commit? ID is ready to go to the specified version.

File deletion

(1) You deleted a file in the workspace and want to synchronize the changes to the remote warehouse.

Git status to view the current status, show that the file in the current workspace has been deleted, use git RM filename command to delete the file in the version library, and then git commit to upload to the current branch.

(2) You deleted a file in the workspace by mistake and want to recover it from the remote warehouse. (if you have submitted the version library before deleting this file in the workspace)

Git checkout — filename

Git checkout is actually to replace the files in the workspace with the files in the version library. No matter whether the workspace is modified or deleted, you can restore the files with one click. However, you can only restore the files to the latest version in the version library. If you make some changes after submitting the version library but do not submit them in time, GIT will not automatically record these changes for you.

Branching operation

First of all, let’s understand the concept of branch. It has been mentioned before that git will automatically create a master branch for us. However, when developing a multi person project, we can’t all submit changes to the main branch, which has great security risks. At this time, GIT encourages us to use the branch to complete tasks. The head pointer points to the current branch, and everyone goes to their own The files submitted on the branch do not interfere with each other. Usually, you can use branches to manage different functional modules when you develop your own projects. Finally, you can use the merge branch command to integrate the files together. This is the same as working directly on the master branch, but the process is safer.

That is to say, in the actual development, the master branch should be very stable, only used to release new versions, and usually can’t operate on it. We can do specific operations on dev, merge everyone’s branches into dev branches, and then merge dev branches into the master when the version is released.

Create branch

Git checkout – B branch name

The GIT checkout command plus the – b parameter indicates creation and switching, which is equivalent to the following two commands:

$git branch branch branch name create branch

$git checkout branch name switch branch

Push locally created branches to remote

Git push origin branch name

View branch

The GIT branch command lists all branches, and the current branch is preceded by a * sign.

Git branch – R view remote branch

Git branch – a view all branches

Merge branch

Git merge branch name (Note: to switch back to the branch to be merged before merging, you cannot merge under the current branch)

Delete branch

Git branch – D branch name

Git branch – D branch name forcibly deletes a branch that has not been merged. By default, it is not allowed to delete a branch that has not been merged.

Clone remote warehouse

Git clone warehouse address the warehouse address can be found on the front page of the warehouse, and it can be cloned locally through the clone command.
GitHub roaming Guide
The use of GitHub is simply introduced here, but its functions go far beyond this. There’s an answer. How to use GitHub effectively? Some people use GitHub to put resumes, write blogs, write books and read information. Some people use GitHub as a circle of friends and microblogs, interact with technical bulls, and post links. Those who are interested can pay attention to it:…

In a word, it’s like a treasure. There are always bright spots and places worth learning to explore.

Leave a Reply

Your email address will not be published.