Git upload files, folders, projects to Github

Git upload files, folders or projects to Github

  • Learn Git basics

  • Configure Git, SSH

    • Download and install Git
    • bind user

      $ git config --global user.name "Your Name"
      $ git config --global user.email "[email protected]"

    • Configure SSH

1. In the user's home directory, check whether there is a .ssh directory. If so, check whether there are two files, id_rsa and id_rsa.pub, in this directory. If there are already, you can directly skip to the next step. If not, open Shell (GitBash under Windows), create an SSH Key, and press Enter without setting the password.

$ ssh-keygen -t rsa -C "[email protected]"

If everything goes well, you can find the .sshdirectory , and there are twoid_rsa files in it. These two are the key pair of . id_rsa is the private key, which cannot be leaked . It is the public key, which can be safely told to anyone. Open ( ) with Notepad and get the ssh key public key.id_rsa.pubSSH Keyid_rsa.pubid_rsa.pubC:\Users\Administrator\.ssh

2. Add ssh key to Github account. Log in to Github, expand the small triangle of your profile picture, click settings, then open the SSH keysmenu, click Add SSH keyAdd Key, and fill in the title.

  • build warehouse

Fill in the repository name, Initialize this repository with a README is optional, it is recommended to select it when creating , you can save a step later. After filling in, click Create repository to complete the establishment of the warehouse

  • clone the repository

If it is a brand new project without any files, you can skip this step without cloning the repository. Open Git Shell and enter the command line. First, we need to clone our new repository on GitHub. Before initializing the repository, make sure that the certified public key is correct

$ ssh -T [email protected]

If you receive a successful confirmation message, you can start cloning the remote repository (take one of my projects as an example)

$ git clone https://github.com/jerryhanjj/baike_spider.git

The address of the remote warehouse can be found on your own Githubproject (take mine as an example)

Get remote warehouse address

After cloning the warehouse, the project folder and files appear in the folder, enter the project folder, and initialize it

$ git init
  • Upload README file

If the Create file is not checked when creating the Githubwarehouse , README.mdthe README.mdfile , otherwise an error will be reported when uploading the file. If it is already checked, you can skip this step.

$ git init
$ touch README.md
$ git add README.md
$ git commit -m 'first_commit'
$ git remote add origin https://github.com/jerryhanjj/baike_spider.git
$ git push origin master
  • upload project

Track all files and folders in the project folder

$ git add . 

Enter the submission description for this time, and prepare to submit the tracked file of the changes in the staging area. The description content is in single quotation marks.

$ git commit -m 'first_commit'

Associate the remote repository, after adding, the name of the remote repository is origin, this is the Gitdefault name, it can also be changed to something else, but originthis name is a remote repository at a glance.

$ git remote add origin https://github.com/jerryhanjj/baike_spider.git

If there is an error fatal: remote origin already existsin the association, execute the following statement and then perform the association

git remote rm origin

Push all the contents of the local library to the remote library

$ git push -u origin master

If there is an error while pushing error:failed to push som refs to......., execute the following statement

git pull origin master

GithubPull the files on the remote warehouse down and merge them and push them up again

Guess you like

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