【Git】遠程倉庫

1、建立SSH Keygit

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

...

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


2、登錄GitHub => 打開「Personal settings」 => "SSH Keys" => "New SSH Keys"github

複製 id_rsa.pub內容到「Key」中並保存「Add SSH Key」。shell

https://github.com/settings/sshssh


3、添加遠程庫code

https://github.com/new 內存

填寫repository name => "create repository"
rem


4、把本地已有git倉庫關聯到遠程(先有本地倉庫,後有遠程倉庫,如何關聯)get

$ 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            => 把本地新的提交推送到遠程


5、從遠程倉庫克隆(先建立遠程倉庫,而後從遠程倉庫克隆)it

$ git clone git@github.com:harrywu0913/git-test.git [new_repo_name]
相關文章
相關標籤/搜索