Use the git tool under Windows to upload code to github to step on the pit record

Use the git tool under Windows to upload code to github to step on the pit record

background

  • Since the previous projects were all version controlled through svn, now the company's projects use git, and I usually have a small project for practicing hands. I try to upload the project to my github for management during the weekend, and I should be familiar with it. Although the operation of git is a simple operation, it still takes some effort because I have not been familiar with it, and some of the points of attention are recorded.

    The first step is to download git

  • Since it is an operation under windows, the windows version of git is downloaded: the
    URL is https://gitforwindows.org

    The second part creates a local warehouse

  • 1. Find your own project directory, of course, you can also find another place and enter the selected folder:
  • 2. After installing git, right-click in the folder to see the git related menu, as shown below

  • 3. ClickGit Bash Here
  • 4. Perform command operations in the pop-up black window
    [The above 3-4 steps can also be operated directly in cmd, which will not be repeated here]

    • Initialize the current folder as a local Git repository
      • $git init
    • After initialization, set a global account, which is equivalent to a registration of a local Git warehouse account. Submitting code in the future can indicate the information of the submitter.
    • Hand over all the code under the folder to git management, because I directly selected the project code workspace, so I submitted all the code directly without ignoring it. If you have other needs, you can refer to other blogs if you have time to sort them out.
      • $git add *
    • Submit all the code under the folder to the local warehouse. In fact, if your workspace and the local warehouse are not in the same place (I directly use the workspace where the code is located as the local warehouse), you need to add the changed files to the local The warehouse can also be said to be a staging area. The next step is to submit the modified or newly added code that has been prepared to be submitted in the local warehouse or staging area to the remote warehouse.
      • $git commit -m "push All of my code to my github!"
    • Associate a local repository with a remote repository
      • $ git remote add origin xxx remote warehouse address xxx
    • Push local repository code to remote repository
      • $ git push -u origin master
        • If this is the first submission, an error will be reported here:

          git "Could not read from remote repository.Please make sure you have the correct access rights.
        • The reason for this error is that when the local is connected to the Yuanzeng warehouse, it needs to verify whether the local and remote warehouses have a common key to ensure a secure connection.
        • Solution :
        • Enter the command, type it, and then press Enter three times (the three Enters actually skip the process of entering the password. This password is the password for each submission in the future, not the password of github. For convenience, it is not entered directly here. There is no password when submitting to the remote warehouse in the future), and then open the directory according to the address displayed on the screen (as shown below):
        • Select the second option here, open it in Notepad, it is recommended to use notepad++ to open, and then copy the full text.
        • Open github and select "settings" in the upper right corner

        • Click on "SSH and GPG keys" on the left

        • "New SSH keys" in the upper right corner
        • However, just fill in one title at random, paste the copied key below and it will be ok.
    • At this time,$git push -u origin master no error will be reported if you execute it again.

When operating ssh in the cmd black window, if the ssh command cannot be found, it is because the system environment variable does not find the file "ssh-keygen.exe", you only need to search for this file locally, and then add the path of this file to " path" environment variable, as shown in the figure.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325336404&siteId=291194637