Git local repository is associated with Github remote repository

If you have created a Git repository locally (already git init), and want to create a Git repository on GitHub, and synchronize the two repositories remotely, you need to use SSH Key, github gets your public key You will know that the content is pushed by you.

 

Configuration of SSH Key under Git Bash:

1. Open Git Bash under Windows, create an SSH Key, and enter the password as prompted. You can press Enter all the way without filling in the password.

$ ssh-keygen -t rsa -C " Register Email "

Then there are two files under the user's home directory /.ssh/, id_rsa is the private key, and id_rsa.pub is the public key.

 

2. Get the key, copy it, and open the id_rsa.pub file under .ssh. The content inside is the content of the key.

$ cat ~/.ssh/id_rsa.pub

 

3. Log in to GitHub, open the "SSH Keys" page, and paste the entire contents of cat

4. Test whether the ssh key is successful, if you've successfully authenticated, but GitHub does not provide shell access appears. This means that you have successfully connected to github.

ssh -T [email protected]

 

Operations between remote libraries and local libraries:

1. Clone a copy from remote to local can be done through git clone

Git supports HTTPS and SSH protocols, SSH is faster

$ git clone [email protected]:nanfei9330/xx.git

 

2. The local library is associated with the remote library, and run the command in the local warehouse directory:

Prerequisite: Local warehouse initialization

$ git remote add origin [email protected]:nanfei9330/learngit.git

Please replace it with the SSH of your own repository

 

3. Push everything from the master branch

$ git add .
$ git commit -m "test"
$ git push -u origin master

The first use adds the -u parameter to push the content and associate the branch.

After the push is successful, you can see that the remote and local content are exactly the same. Next time, as long as the local commit is made, you can pass the command:

$ git push origin master

Push the latest content to Github

 

==========================================

Create the text test.txt locally, run:

$ git add text.txt
$ git commit -m "add new file" 
$ git push origin master

Then you can see the synchronization on github

 

other:

Retrieve the update of a branch of the remote host, such as

$ git pull origin master

Reference from:
https://www.cnblogs.com/tinyphp/p/5025311.html

Guess you like

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