Git tutorials in the remote warehouse details _ Tips

Source: Internet
Author: User
Tags ssh git commands

Git Remote Repository

Git does not have a central server like SVN.

The GIT commands we use at the moment are executed locally, if you want to share your code with GIT or work with other developers. You need to put the data on a server that other developers can connect to.

This example uses Github as a remote repository, and you can read our Github concise tutorials first.

Add a remote Library

To add a new remote repository, you can specify a simple name for future references, and the command format is as follows:

git remote add [shortname] [url]

This example takes GitHub as an example as a remote warehouse, if you do not have GitHub can be registered in the official website https://github.com/.

Because the transmission between your local git warehouse and the GitHub warehouse is encrypted via SSH, we need to configure the authentication information:

Use the following command to generate the SSH Key:

$ ssh-keygen-t rsa-c " youremail@example.com "

The your_email@youremail.com in the back will be changed to the mailbox you registered on the GitHub, then ask for confirmation of the path and enter the password, we use the default all the way to return to the line. Successful words will be generated under ~/. SSH folder, go in, open id_rsa.pub, copy key inside.

Back to GitHub, enter account settings (accounts configuration), the left choice ssh keys,add ssh key,title casually fill, paste on your computer generated Key.

To verify success, enter the following command:

$ ssh-t git@github.com
Hi tianqixin! You have ' ve successfully authenticated, but GitHub does not provide shell access.

The following order indicates that we have successfully connected Github.

After the login, click on "New Repository" as shown in the following image:

After the w3cschool.cc (remote warehouse name) is filled in repository name, the other defaults, and clicking the "Create Repository" button creates a new Git repository successfully:

After the creation is successful, the following information is displayed:

The information above tells us that a new warehouse can be cloned from this warehouse, or the contents of the local warehouse can be pushed to the GitHub warehouse.
Now, we run the command under the local warehouse according to GitHub's prompts:

$ ls
README
w3cschool Rookie tutorial test. txt
test.txt
$ git Remote add Origin git@github.com:tianqixin/ W3cschool.cc.git
$ Git push-u origin master
counting objects:21, done.
Delta compression using up to 4 threads.
Compressing objects:100% (15/15), done.
Writing objects:100% (21/21), 1.73 KiB | 0 bytes/s, done.
Total (Delta 4), reused 0 (Delta 0) to
git@github.com:tianqixin/w3cschool.cc.git
 * [New branch]   Master -> Master
Branch Master set up to track remote Branch master from Origin.

The following commands should be copied according to the place where you successfully created the new warehouse in GitHub, not according to the commands I provided, because our GitHub username is different and the name of the warehouse is different.

Next we return to the warehouse created by Github and we can see that the file has been uploaded to the Github:

View the current remote library

To see which remote warehouses are currently configured, you can use the command:

Git remote

$ git Remote
Origin
$ git Remote-v
Origin git@github.com:tianqixin/w3cschool.cc.git (fetch)
origin Git@github.com:tianqixin/w3cschool.cc.git (push)

When executed with the-v argument, you can also see the actual link address for each alias.

Extracting remote repositories

Git has two commands to extract updates from a remote repository.

1, from the remote warehouse to download new branches and data:

git fetch

After this command is executed, you need to perform a remote branch of git merge to your branch.

2. Extract data from the remote warehouse and try to merge to the current branch:

Git pull

The command is to execute the GIT merge remote branch immediately after executing git fetch to any branch you are in.

Assuming you have a remote repository configured and you want to extract the updated data, you can first execute git fetch [alias] to tell Git to get it with the data you don't have, and then you can execute git merge [Alias]/[branch] To merge any updates on the server (assuming someone is pushed to the server at this point) into your current branch.

Next we click on "W3cschool Rookie tutorial test. txt" on Github and modify it online. Then we update the changes locally.

$ GIT fetch origin
warning:permanently added the RSA host key for IP addresses ' 192.30.252.128 ' to the list of known Ho Sts.
Remote:counting Objects:3, done.
Remote:compressing objects:100% (2/2), done.
Remote:total 3 (Delta 1), reused 0 (Delta 0), pack-reused 0
unpacking objects:100% (3/3), done.
From github.com:tianqixin/w3cschool.cc
  7d2081c. F5F3DD5 Master   -> Origin/master

The above information "7d2081c. F5F3DD5 Master-> origin/master "description The Master branch has been updated and we can synchronize updates to local using the following command:

$ git merge origin/master
updating 7d2081c. F5f3dd5
Fast-forward
 "w3cschool\350\217\234\351\270\237\346\225\231\347\250\213\346\265\213\350\257\ 225.txt "| 1 +
 1 file changed, 1 insertion (+)

Push to remote Warehouse

Push your new branch and data to a remote warehouse command:

git push [alias] [branch]

The above command pushes your [branch] branch into the [branch] branch on the [alias] remote Repository, as shown in the following example.

$ git merge origin/master
updating 7d2081c. F5f3dd5
Fast-forward
 "w3cschool\350\217\234\351\270\237\346\225\231\347\250\213\346\265\213\350\257\ 225.txt "| 1 +
 1 file changed, 1 insertion (+)
BOGON:W3CSCHOOLCC tianqixin$ vim w3cschool Rookie tutorial test. txt 
BOGON:W3CSCHOOLCC tianqixin$ git push Origin master
Everything up-to-date

Delete Remote Warehouse

Delete Remote Warehouse You can use the command:

git remote rm [alias]

 $ git remote-v Origin git@github.com:tianqixin/w3cschool.cc.git (fetch) Origin Git@github 
. Com:tianqixin/w3cschool.cc.git (push) $ git remote add origin2 git@github.com:tianqixin/w3cschool.cc.git $ git remote-v
Origin Git@github.com:tianqixin/w3cschool.cc.git (Fetch) Origin git@github.com:tianqixin/w3cschool.cc.git (push) Origin2 git@github.com:tianqixin/w3cschool.cc.git (Fetch) origin2 git@github.com:tianqixin/w3cschool.cc.git (push) $ Git remote rm origin2 $ GIT remote-v Origin git@github.com:tianqixin/w3cschool.cc.git (fetch) Origin GIT@GITHUB.COM:TIANQ Ixin/w3cschool.cc.git (push) 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.