Git remote repository operation notes
- This note is mainly for Github to write a related remote operation notes, also related SSH key generation and use operations.
Connecting a remote warehouse
- I need to operate on Git’s remote repository, which WILL be my MyStudyNotes repository
- The first step is to go into the local repository where we need to establish a connection and execute the following code
git remote add origin https://github.com/china-renqing/MyStudyNotes.git
- When you’re done, tell your local Git repository, and subsequent operations will automatically connect to the specified address
- The first step is to go into the local repository where we need to establish a connection and execute the following code
The simplest remote warehouse operation
-
Commit to the remote repository
git push -u origin master
- The code change means that the action will be committed to the master branch of the remote repository, and future Git pushes will be automatically committed to the master branch.
- The master can be changed to another branch and can be committed to another branch later.
-
Clone the project locally
git clone https://github.com/china-renqing/MyStudyNotes.git
-
Clone the specified branch locally (clone the master branch here)
git clone -b master https://github.com/china-renqing/learn-MVC.git
-
Pull items to local
git pull
// Execute this code
-
Delete the branch of the remote repository
- Delete branch1 (branch1) locally
git branch -d branch1
Execute after)git push origin:branch1
I can delete branch 1.
- Delete branch1 (branch1) locally
-
Push labels to remote repositories
- Push a specific label to the local repository:
Git push origin v0.2
- Push all tags to local repository:
git push origin --tag
- Push a specific label to the local repository:
-
Delete the label for the remote repository
- Delete the specified label:
Git push origin: ref/tags/v0.2
- Delete the specified label:
Using SSH Keys
- Start by generating an SSH key on your own computer
ssh-keygen -t rsa -C "[email protected]"
// Follow your email address- Open the id_rsa.pub file in C:\Users\YourName\. SSH by default.
- Add the obtained public key to GitHub corresponding to add SSH key after adding, as shown below: *
- Check whether the connection is successful
ssh -T [email protected]
// Here is the test whether to connect to GitHubssh -T [email protected]
// Test whether it is connected to Gitee
- Note that after the connection is successfully detected, it is also necessary to tell the local warehouse which warehouse is connected before subsequent operations can be performed
- Example:
git remote add origin https://github.com/china-renqing/MyStudyNotes.git
- Example:
The future patching
- If there is any wrong place, I hope you put forward, thank you.