Git add, view, extract, push, delete remote repository (GitHub) tutorial, gitgithub
Add remote database
To add a new remote repository, you can specify a simple name for future reference. The command format is as follows:
git remote add [shortname] [url]
This example uses Github as a remote repository. If you do not have Github, you can register it on the official website.
Because the transmission between your local Git repository and GitHub repository is encrypted through SSH, We need to configure verification information:
Run the following command to generate an SSH Key:
$ ssh-keygen -t rsa -C "youremail@example.com"
After the your_email@youremail.com is changed to your registered mailbox on github, will ask to confirm the path and enter the password, we will use the default one-way carriage return on the line. If it succeeds ~ /, Generate the. ssh folder, go in, open id_rsa.pub, and copy the key.
Go back to github and enter Account => Settings ).
Select SSH and GPG keys on the left, click the New SSH key button, and set the title. You can enter the title and paste the key generated on your computer.
The page is shown as follows:
To verify the success, enter the following command:
$ ssh -T git@github.comHi tianqixin! You've successfully authenticated, but GitHub does not provide shell access.
The following command indicates that we have successfully connected to Github.
After logging on, click "New repository", as shown in:
Enter runoob-git-test (Remote Repository name) in repository name. Keep the default configurations for others. Click "Create Repository" to Create a new Git repository:
After the creation is successful, the following information is displayed:
The above information tells us that we can clone a new warehouse from this warehouse, or push the content of the Local warehouse to the GitHub warehouse.
Now, run the following command in the local repository as prompted by GitHub:
$ Mkdir runoob-git-test # create a test directory $ cd runoob-git-test/# enter the test directory $ echo "# cainiao tutorial Git test"> README. md # create README. md file and write the content $ ls # view the file README $ git init # initialize $ git add README. md # Add the file $ git commit-m "to add README. md file "# submit and remarks [master (root-commit) 0205aab] add README. md file 1 file changed, 1 insertion (+) create mode 100644 README. md # submit to Github $ git remote add origin git@github.com: tianqixin/runoob-git-test.git $ git push-u origin master
The following command copies the repository where you successfully created a new repository on GitHub, instead of the commands provided by me, because our Github user names are different and the repository names are different.
Next, return to the repository created on Github, and you can see that the file has been uploaded to Github:
View the current remote database
To view which remote libraries are configured, run the following command:
git remote
$ git remoteorigin$ git remote -vorigingit@github.com:tianqixin/runoob-git-test.git (fetch)origingit@github.com:tianqixin/runoob-git-test.git (push)
When the-v parameter is added, you can also see the actual connection address of each alias.
Extract remote Repository
Git has two commands to extract updates from a remote repository.
· Download new branches and data from a remote Repository:
Git fetch // After the command is executed, execute the git merge remote branch to your branch.
· Extract the database from the remote warehouse and try to merge it to the current Branch:
Git merge // This command is executed immediately after git fetch is executed and then the git merge remote branch is executed to any branch where you are located.
Suppose you have configured a remote repository and want to extract the updated data, you can first execute git fetch [alias] To tell Git to get the data that you do not have, then you can execute git merge [alias]/[branch] to merge any updates on the server (assuming someone pushed to the server at this time) to your current branch.
Next, click "README. md" on Github and modify it online:
Then we update and modify it locally.
$ git fetch originremote: Counting objects: 3, done.remote: Compressing objects: 100% (2/2), done.remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0Unpacking objects: 100% (3/3), done.From github.com:tianqixin/runoob-git-test 0205aab..febd8ed master -> origin/master
The above information "0205aab .. febd8ed master-> origin/master" indicates that the master Branch has been updated. We can use the following command to synchronize updates to the local machine:
$ git merge origin/masterUpdating 0205aab..febd8edFast-forward README.md | 1 + 1 file changed, 1 insertion(+)
View the content of the README. md file:
$ Cat README. md # cainiao tutorial Git testing # Content modified for the first time
Push to remote Repository
Push your new branch and data to a remote warehouse command:
git push [alias] [branch]
The preceding command pushes your [branch] branch to the [branch] branch on the [alias] Remote repository. The instance is as follows.
$ Touch runoob-test.txt # add file $ git add runoob-test.txt $ git commit-m "add to remote" master 69e702d] add to remote 1 file changed, 0 insertions (+ ), 0 deletions (-) create mode 100644 runoob-test.txt $ git push origin master # push to Github
Return to our Github repository and you can see and submit the file:
Delete remote Repository
Git remote rm [alias]
Instance
$ Git remote-vorigingit@github.com: tianqixin/runoob-git-test.git (fetch) origingit@github.com: tianqixin/runoob-git-test.git (push) # add repository origin2 $ git remote add origin2 git@github.com: tianqixin/runoob-git-test.git $ git remote-vorigingit@github.com: tianqixin/runoob-git-test.git (fetch) origingit@github.com: tianqixin/runoob-git-test.git (push) origin2git@github.com: tianqixin/runoob-git-test.git (fetch) origin2git@github.com: tianqixin/runoob-git-test.git (push) # Delete repository origin2 $ git remote rm origin2 $ git remote-vorigingit@github.com: tianqixin/runoob-git-test.git (fetch) origingit@github.com: tianqixin/runoob-git-test.git (push)