Git, GitHub entry

1: Git and GitHub Getting Started

1: What is Git What is GitHub??

  • Git Git is a distributed version control system open source, and can be effectively processed at high speed from very small to very large project version management. Speaking of Git, we must first understand what is a distributed version control and management systems.
  1. Version Control Version control is the management of collaboration among many people in the software development process, a variety of code, configuration files, and documentation changes. The main function is to track file changes. It will be when and who changed what files and other information faithfully recorded. E.g:

  2. Distributed Management mentioned distributed management, have to say the birth of Git.
    Linux Torvalds created the open-source Linux, the open source world by enthusiastic volunteers to write code for Linux systems. But as more and more people to write their code, the team getting larger and larger, Linux Torvalds only through their own integration code is no longer very realistic, be resolved by management code version control system is the best solution. But I Linux and other free and CVS and SVN version control system is extremely prevalent in disgust at that time. The reason is that these CVS or SVN version control system is a centralized management system, and each code needs to be submitted networking. So Linux chose a paid commercial version control system BitIKeeper, BitKeeper authorized to the Linux community can use this free version control system. However, Linux community itself cattle were gathered, BitKipper company found that, Linux community was trying to crack BitKeeper protocols, and thus, BitKeeper Linux open source community partnership with the termination. Still later, Linux I spent two weeks using the C language to write a distributed version control system is Git. Git has now become the most popular distributed version control system GitHub in 2008 on the line, countless open-source project started to migrate to GitHub. After talking about the birth of Git, we go back to the topic, talk about distributed vs centralized.

  • Centralized version control system on behalf of: SVN


    Centralized version control system SVN represented. Centralized storage repository on a central server. Multiplayer cooperative projects, each computer must start with a central server to get the latest version, add or modify the code after a good, then your code pushed to a central server. Once the central server fails or crashes, although there is a central server from the pull-down code on a personal computer programmer, but with all the historical versions of items on a central server, you want to fix the previous version of history is very difficult.

  • Distributed version control systems on behalf of: Git


    Distributed version control systems is no such concept of a central server, each person's computer is a complete version of the library, of course, distributed version control system often exists a computer to act as a central server, and programmers to push the latest update version. Even so-called "central server" hang up on everyone's computer will retain version history information. This point of view, the distributed version control security than centralized version control is higher. Of course, Git SVN compared to the advantages far more than these, see: Git differs from SVN .

  • GitHub GitHub is an open source project hosting platform proprietary software, on-line in 2008. GitHub only supports git repository as the only format hosting.

2: GitHub configuration work

  1. First of all, registration GitHub account, click settings Once you register the location of the picture.

  2. Profile found in the left hand column of the "SSH and GPG keys", then you'll see the "New SSH key". This button, do not worry to click it, you will see the following have a clickable link "Check out our guide to generating SSH keys or troubleshoot common SSH Problems ", click.  Generating SSH Keys and third choice: Generating A new new SSH Key and Adding to IT at The SSH-Agent .

  3. According to the above prompts: Open GitBash, enter the command: ssh-keygen -t rsa -b 4096 -C "[email protected]"After input is complete, knock three times a carriage return, you can. Back attention to the need to fill in your own mailbox.

  4. Run command ls -a ~/.ssh. When executing the command ssh-keygen -t rsa -b 4096 -C "[email protected]", the home directory will generate a directory of .ssh. Run the command ls -a ~/.ssh, you can see there are two files "id_rsa" and "id_rsa.pub" in the .ssh directory. These two things public and private keys, is the key and lock between your local Git repository to GitHub. Where "id_rsa" is the key, and "id_rsa.pub" that is locked.

  5. Then click just said "New SSH key" button, Title is the name of your SSH key, key contents of the following will need your public key to copy all the contents into it, execute commands on GitBash cat ~/.ssh/id_rsa.pub. Then "ssh all content -rsa "to" [email protected] "copy and paste the key inside. After the addition is complete click "Add SSH key" button.

  6. Enter the command on GitBash ssh -T [email protected]If you see returns this information:. Hi DobbyKimmy! You've successfully authenticated, but GitHub does not provide shell access., The configuration was successful. If it fails, it runs on GitHub rm -rf ~/.sshafter the restart from the first step. If in the future, buy a new host, then you can re-generate a SSH key on a new PC, it can coexist with previous key.

3: Git configuration work

git config --global user.name 你的英文名                                                   
git config --global user.email 你的邮箱                                                     
git config --global push.default matching
git config --global core.quotepath false
git config --global core.editor "vim"
复制代码

This five sentences must be performed after the configured Git, you can guarantee that will not complain.

4: local use of Git

  1. git initSelect an empty directory, GitBash Here, then execute the command git init. The role of the command is initialized After executing the command, create a directory called .git in the current directory.

  2. git status -sb Next, create two files in the current directory, such as: index.html, that is, enter the command:

    touch index.html
    mkdir css
    cd css
    touch style.css
    cd ../
    复制代码

    Run git status -sbafter, will return this result:

    ?? css/
    ?? index.html
    复制代码

    Command git statusis used to view the current status of git, -s behalf summary that is displayed: summary; -b represents a branch that is displayed: branch. After re-create the file, git does not know how to deal with these two documents, so there will be "??" such a symbol.

  3. git add

    Command git addfiles can be created to the staging area, you can use: git add index.htmlbefore using git add css/style.cssagain and again to add the file into the staging area, it is possible once git add .this command indicates that at one time all of the directory changes are added to the current temporary memory area. After re-execute the command staging area complete added again use git status -sbcan be found in the original red "??" become green "AA". A means is add, also mean, you tell git, I want to change the files added to the repository.

  4. git commit -m"xxx"

    git commit -m"xxx"You can add command over the content, namely: git meaning in the context of the temporary area formally submitted to the local repository (.git is the local repository) -m is the message that is: The submission of explanatory information for you, and this parameter -m It is a must have. In addition to the -m parameter, as well as a -a parameter: Use the command git commit -am "xxx"This command will work the local area has not been modified into a staging area git up documents to be submitted, the equivalent git add .command with git commit -m"xxx"two commands together use, and this command ensures that all changes be submitted to the local repository. In the run to completion git commit -am "添加了一些变动"command, use the command git status -sb, found no change in the file because the file change has been recorded in the warehouse then you can use the command: git logView historical change, change history information is as follows:

    Author: DobbyKim <[email protected]>
    Date:   Thu Apr 4 15:36:37 2019 +0800
        添加了一些文件
    复制代码
  5. git log

    As already used the git logcommand, and git logis a very important command, you can view all change history information item, and you can see updates the person's name and email account.

  6. Change file

    After submitting to a local warehouse, we edit index.html save after writing something, which we then look git status -b, you can see the git status becomes:

    M index.html
    复制代码

    M color is red, its meaning is Modified, represents the index.html file has been modified, if you want to save changes to the repository, you need git add .to save changes to the staging area, and then commit execute the command git commit -am "编辑了index.html". After executing the add and commit operation, use the command git status -sbfound no change in the file, use git log:

    $ git log
    commit c96f1b9c58c517501d1d7544ef5ff76f01078d25 (HEAD -> master)
    Author: DobbyKim <[email protected]>
    Date:   Thu Apr 4 16:04:48 2019 +0800
    
        编辑了index.html
    
    commit 138a29bcdd7b2b2a19e7d5a7f8150da5666623f9
    Author: DobbyKim <[email protected]>
    Date:   Thu Apr 4 15:36:37 2019 +0800
    
        添加了一些文件
    
    复制代码

5: Git repository locally uploaded to GitHub

  1. First create a new empty warehouse on GitHub:

    Only need to set the name of the warehouse, the other not and will not fill, because if it is not filled in the empty warehouse.
  2. Follow the instructions on the SSH GitHub first select the path. GitHub command prompt will appear in the following empty warehouse after the establishment of good. create a new repository on the command line
echo "# demo" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin [email protected]:DobbyKimmy/demo.git
git push -u origin master
复制代码

push an existing repository from the command line

git remote add origin [email protected]:DobbyKimmy/demo.git
git push -u origin master
复制代码

Local warehouse uploaded to GitHub only need to do two git push and git remote command. origin is [email protected]:DobbyKimmy/demo.gitthe warehouse code, the role of remote commands is to establish links with local repository GitHub remote repository. sucked the local repository git push content pushed to the remote repository, code, master or remote repository on behalf of origin of the default main branch.

6: GitHub repository on the download to the local

Example: Create a GitHub repository, this time need to establish a non-empty warehouse.


respository name or the name of the warehouse, description descriptive information for the warehouse, check the Initialize this repository with a README file is used to initialize README.md when creating warehouse. The role of which is to ignore file .gitignore file in Git do not want to submit, you can make some configuration files in .gitignore to refrain from submitting certain documents, such as: write on /node_modules/ , /.vscode/ you can avoid node_modules / and .vscode / upload directory on GitHub. License is an open source license, and there I chose the MIT open source license. After you've created a warehouse, copy the link:

To the directory you want to clone under on GitBash input: git clone "复制的SSH URL" you can download the warehouse.

7: Upload updated

After downloaded to the local repository, upload the update is very simple, just has to perform:

  1. git add.
  2. git commit -am "xxx"
  3. git pull which the git pullrole of local synchronization command is to make good the remote repository code. If a project, if you have made, your programmer colleagues have made changes and submitted a first step in the code to you, then your local repository of code is not the latest version of the. This time code is uploaded to a remote repository error will occur, only need to first upload the latest code from a remote repository can pull down again.
  4. git push

8: git pull and git clone difference

In the use of these two commands, from the application point of view scene, git clone is no local storage, remote warehouse download, git commit new sucked remote repository pulled the pull command data locally, then the local warehouse merge. git clone git pull and are downloaded code. An identical clone from a remote server repository to the local copy of the entire repository, called a clone, this is a process from scratch. git pull that got me to update remote branches to local warehouse operation, the equivalent of git pull, get the latest version from a remote repository, and then merge with the local branch of the process, it is from there to a comprehensive, from asynchronous to synchronous process .

Guess you like

Origin blog.csdn.net/weixin_34380296/article/details/91398287