您的位置:首页 > 其它

【Git】远程仓库

2016-02-15 00:00 148 查看
一、创建SSH Key

$ ssh-keygen -t rsa
...
...

...

$ ls ~/.ssh/
id_rsa		id_rsa.pub	known_hosts


二、登陆GitHub => 打开“Personal settings” => "SSH Keys" => "New SSH Keys"

复制 id_rsa.pub内容到“Key”中并保存“Add SSH Key”。

https://github.com/settings/ssh

三、添加远程库

https://github.com/new

填写repository name => "create repository"

四、把本地已有git仓库关联到远程(先有本地仓库,后有远程仓库,如何关联)

$ git init test-git
$ git remote add origin git@github.com:harrywu0913/git-test.git        => 把本地仓库关联到远程git-test
添加后远程的仓库名称叫做origin(是git的默认名称,也可以修改成其他的)
$ cd test-git
$ touch readme.txt
$ git add readme.txt
$ git commit -m "initial commit"    => 在本地仓库中提交些内容

$ git push -u origin master         => 把本地仓库push到远程仓库,即把当前分支master推送到远程origin分支
第一次要加-u git会把本地的master分支内存推送到远程新的master分支,还会把本地的master分支和远程的master分支关联。

$ cd test-git
$ mkdir a
$ touch a/a.txt
$ git add a/*
$ git commit -m "add directory a"
$ git push origin master            => 把本地新的提交推送到远程


五、从远程仓库克隆(先创建远程仓库,然后从远程仓库克隆)

$ git clone git@github.com:harrywu0913/git-test.git [new_repo_name]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: