Use Git on Window10 to interconnect with Github remote warehouse

Article Directory

  1. Register a Github account

  2. Create a warehouse (you can also create it later, see point 9)

  3. Install Git
    install Git on Windows is very simple, directly in Git official website to download the installer, and then press the default installation.

  4. After the installation is complete, in the start menu bar -> All Programs, you will find Git->Git Bash
    Insert picture description here
    as shown in the figure above, which means that the Git installation is successful!

  5. Tell Git your username and email (ie your GitHub username and email), enter the following command to set
    Insert picture description here

    Using the -global parameter is to make all Git repositories on this machine use the username and mailbox, and different repositories can also use different usernames and mailboxes. But we usually only use one GitHub account, so just set it up directly like this

  6. Create a local warehouse on your own computer (a warehouse can be simply understood as a directory, and each directory contains a warehouse)

    Create a new folder (such as the E: Git/ directory) anywhere on your computer. This directory will serve as the Git management directory, and all warehouses will be created in this directory.
    Insert picture description here

    Create a new local warehouse under this directory, named data-mining 1. cd to
    this directory
    Insert picture description here
    2. Create a new directory data-mining, and then cd to the data-mining directory
    Insert picture description here
    3. Change the data-mining directory into a warehouse that can be managed by Git
    Insert picture description here
    After running this command, you can generate a hidden .git folder in the data-mining directory, indicating that the initialization is successful, and the directory can be managed by Git. For the
    above operations, we have created an empty warehouse data-mining

  7. Add files to the warehouse, for example: create a new helloworld.py file in the warehouse directory, adding the file to the warehouse requires the following two steps:

    1. Use the command git add to add the file to the warehouse
    Insert picture description here
    Insert picture description here

    This means that the helloworld.py project file is added to the warehouse. If you want to add all files, you can also use git add. Directly add all the files in the warehouse directory to the warehouse at one time, and use the git commit command for the last time. It's a lot convenient.
    2. Use the command git commit to submit the file to the warehouse
    Insert picture description here
    -m. The input is the description of this submission. It is better to be meaningful, so that you can easily find the change record from the history record.

  8. Remote warehouse settings
    Generally speaking, we don't just build GIt warehouses locally, but the more common situation is to interconnect the local warehouses with the remote warehouse GitHub. Since SSH encryption is used, the following settings are required:

    1. Create an SSH Key. In the user's home directory, check if there is a .ssh directory. If so, check if there are two files id_rsa and id_rsa.pub in this directory. If you already have one, you can jump to it directly Next step. If not, open a terminal (open Git Bash under Windows) and create an SSH Key:
    Insert picture description here

    Then enter the password twice again!

    2. Log in to your GitHub, click the Settings option in the upper right corner of the page, click SSH and GPG keys, click New SSH key, and enter Title and Key. Key is the content in your computer’s id_rsa.pub.pub, just copy it directly
    Insert picture description here
    Open id_rsa.pub.pub, you can directly use the cat command to view the public key: cat id_rsa.pub.pub or vim id_rsa.pub.pub to view the local public key. The
    Insert picture description here
    reason why you need to set the SSH key is to identify what you pushed. You pushed it, not someone impersonating it, and Git supports the SSH protocol, so as long as GitHub knows your public key, you can confirm that only you can push.
    If you have two computers, such as one at the company and one at home. Then you can add the public keys of both computers to your GitHub, so that both can be pushed.

  9. Upload from local to GitHub
    Just now we have built a data-mining warehouse locally, so how to upload this warehouse to our remote warehouse GitHub?

    1. Create a new blank warehouse on GitHub and name it data-mining.
    First, click on New repository in the upper right corner of your GitHub homepage, and then write data-mining in the Repository name, don’t check "Initialize this repository with a README", just click Create repository
    Insert picture description here
    Insert picture description here
    2. Go back to our Git Bash interface and set the local The Git library is associated with the remote warehouse just built, enter the following command
    Insert picture description here
    3. The next step is to upload all the files in the local warehouse to GitHub.
    git push -u origin masterInsert picture description here
    Insert picture description here
    If there is an error, fatal: unable to access 'https://github.com/Libra-1023/data-mining.git/': error setting certificate verify locations: CAfile: D:/Git/mingw64/ssl/certs/ca-bundle.crt CApath: nonesee this article to solve it https://blog.csdn.net/sdhongjun/article/details /52144253

    Insert picture description here

    Authorization: Insert picture description here
    It turns out that the ladder was not used, and the ladder was used after a network error, so there is a network warning in front of the Insert picture description here
    upload success and the above sentence is displayed.
    4. Go back to GitHub, enter the data-mining warehouse, and you will find that the helloworld.py file has been uploaded to our GitHub. On the GitHub page, you can see that the content of the remote library is exactly the same as the local one.
    Insert picture description here
    5. After that, after we make any changes in the local data-mining warehouse, we can directly run the following statements to add, submit to the warehouse and upload to the GitHub remote warehouse.
    git add .
    git commit -m "xxx"
    git push -u origin master

  10. Clone from GitHub to a local repository
    We have created a remote repository on GitHub. How to use Git to synchronize the repository on GitHub to the local repository?

    1. Copy the Github warehouse address
    Insert picture description here

    2. Open Git Bash, cd to the /Git directory we created before (there is no data-mining folder in the /Git directory, ignore the operation in the previous section), enter the following command, you can directly clone the GitHub remote warehouse learngit to Locally
    git clone https://github.com/Libra-1023/data-mining.git
    can clone successfully! ! !
    In this way, a data-mining folder will appear in the /Git directory, and all files in the GitHub remote warehouse will be cloned in the /Git/data-mining/ directory (including a .git folder).
    This completes the function of cloning from the GitHub remote warehouse to the local warehouse. This method does not need to run the git init statement, just the above statement.
    After cloning, you can add files, modify projects, etc. in the local warehouse, and then use the following three statements to upload to the GitHub remote warehouse

    git add .
    git commit -m "xxx"
    git push -u origin master

    Generally, after entering the "git push -u origin master" statement, you need to enter your GitHub username and password. But I changed the way of submitting using https to ssh instead of entering the username and password

reference:

  1. Liao Xuefeng Git Tutorial
  2. Red stone

Guess you like

Origin blog.csdn.net/weixin_46649052/article/details/114269552