Prior to using GitHub's desktop version in Windows, the library was built with the help of software. The functionality used is also very limited, just create the library and submit your own code. There is no clear understanding of versioning, rollback, branching, or the structure of git. This time, because of the need to use Git to link github in Ubuntu, you have to be exposed to some GIT commands and have a deeper understanding of Git's ideas. Here's a simple comb for the memo. At the end of the article also attached to my reference blog, interested in further reading.
Some understanding
It's been silly to think about GitHub and git for two different version management tools. Now it's time to realize that Git is a version management tool, and GitHub is just a remote repository. In fact, there is no remote repository of GitHub, and git in your computer builds a local repository or links to other remote repositories.
1. Installation of Git
Enter the command to install Git and review the version to confirm that the installation was successful.
sudo apt-get install gitgit --version
2. Use of Git
First explain some concepts, git is four layers of management code.
- The files in your directory are the first tier
- Buffer, after each add, the files in the current directory will be stored in the cache as a version. Note that not all files are. Typically, after a file is generated, it is marked as "not tracked," but whether it is versioned or selected. For example, some compiled files do not need to be traced. For the need to do version management of the asked pieces, add with add, do not need to delete with clean.
- Local repository, after each commit, the latest version of the cache will be stored in the local repository. A head concept is to be mentioned here. Head is the current version point, and each update or fallback will change the head point, but it will not be deleted for each version in the repository. So even if you fall back to the past, there is a chance to go back to the current version.
- Remote warehouse, after each push, stores the version pointed to by head in the local repository to the remote repository
Here are some of my commonly used commands as memos, the detailed use of the results please refer to my text at the end of the blog link attached.
| Command |
function |
| Git init |
Initialize the Git repository in the local current directory |
| git status |
View the status of the current warehouse |
| Git add-a |
Add all files in the directory to the cache |
| git Add File |
Add the appropriate file to the buffer |
| git commit-m "Info" |
Commit changes in the cache to the local warehouse |
| git log |
View commit records before the current version |
| Git reflog |
View Head's change history, including fallback |
| Git branch-b branch_name |
To build a new branch |
| Git diff |
View the difference between the current file and the cache file |
| Git checkout--file |
Cancels the change, overwrites the buffer's file extract to the current file |
| Git reset--hard version number |
Fallback to the corresponding version number, also can fall back to the future version number |
| Git clean-xf |
Delete all non-tracked files in the current directory |
| git config--global core.quotepath false |
Working with Chinese file names |
These commands are sufficient to handle the versioning of the local repository, and I'll deal with remote repositories below.
2. Git links to GitHub
First of all we think you already have a GitHub account.
Then we're going to set up SSH links. This is a cryptographic protocol for communication. I first compute a pair of public and private keys on my laptop and store the public key in GitHub so that encrypted communication can be initiated locally via SSH. Detailed content can refer to the SSH principle and application (a): remote login.
Create a method, enter a command
ssh-keygen -t rsa -C "[email protected]" //双引号里面是你的常用邮箱
Enter the password after entering, you can not enter directly by pressing "enter" all the way to confirm it. Then find the hidden directory in the root directory of your account (/or/home/your account name, depending on the account you used to execute the above command). ssh/id_rsa.pub file to add the contents to GitHub.
This way you can link to GitHub via SSH. But GitHub as a remote repository, you can link to this repository and keep it in sync. But you can't upload your local repository directly to GitHub. So you should set up a repository in GitHub, then build a repository locally, link the two, and then write to the file to perform version management. The commands used are
git remote add origin [email protected]:<用户名>/<仓库名>.gitgit pull origin master //因为github建立仓库时会有readme.md文件,先要拷贝一份git push -u origin master //将本地仓库链接到master分支上,你当然可以链接到其他分支git push//上传你的本地仓库
There is also a way to build a library and then link to the two places. You can build the library on GitHub and clone it to a local directory.
git clone [email protected]:<用户名>/<仓库名>.git
As for the branch management of team cooperation, because it is not available now, and so on later have the opportunity to try to learn it.
A simple tutorial on git and GitHub
The use of Git in Linux