Git upload files, folders or projects to Github
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
.ssh
directory , 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.pub
SSH Key
id_rsa.pub
id_rsa.pub
C:\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 theSSH keys
menu, clickAdd SSH key
Add 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
Github
project (take mine as an example)
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
Github
warehouse ,README.md
theREADME.md
file , 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 theGit
default name, it can also be changed to something else, butorigin
this 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 exists
in 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
Github
Pull the files on the remote warehouse down and merge them and push them up again