把本地倉庫工程上傳到github上和從gitbu同步工程到本地

來源:互聯網
上載者:User

標籤:from   github   技術   倉庫   root   本地   logo   exec   上傳   

1、在本地產生秘鑰和公開金鑰

[[email protected] git_project]# ssh-keygen -t rsa -C "[email protected]@qq.com"Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa      #在這裡輸入rsa秘鑰所在的目錄Enter passphrase (empty for no passphrase):                                     #輸入jacky-lulu帳號的密碼Enter same passphrase again:                                                    #再次輸入jacky-lulu帳號的密碼Your identification has been saved in /root/.ssh/id_rsa.                        #儲存秘鑰的檔案(id_rsa)Your public key has been saved in /root/.ssh/id_rsa.pub.                        #儲存公開金鑰的檔案(id_rsa.pub)

2、查看公開金鑰

[[email protected] /]# cd /root[[email protected] ~]# ls -al總用量 156dr-xr-x---.  5 root root  4096 12月 31 18:26 .dr-xr-xr-x. 25 root root  4096 12月 31 13:37 ..-rw-------.  1 root root  1595 10月  7 09:49 anaconda-ks.cfg-rw-------.  1 root root 16744 12月 30 21:33 .bash_history-rw-r--r--.  1 root root    18 5月  20 2009 .bash_logout-rw-r--r--.  1 root root   176 5月  20 2009 .bash_profile-rw-r--r--.  1 root root   176 9月  23 2004 .bashrc-rw-r--r--.  1 root root   100 9月  23 2004 .cshrcdrwx------.  2 root root  4096 10月  7 09:51 .gconfdrwx------.  2 root root  4096 10月  7 09:53 .gconfd-rw-r--r--.  1 root root    66 12月 31 17:16 .gitconfig-rw-r--r--.  1 root root 43838 10月  7 09:49 install.log-rw-r--r--.  1 root root 10033 10月  7 09:46 install.log.syslog-rw-------.  1 root root    35 12月 31 18:26 .lesshst-rw-------.  1 root root  3380 12月 11 21:20 .mysql_history-rw-------.  1 root root    78 11月 10 20:19 .mysql_secret-rw-r--r--.  1 root root   879 11月  5 18:14 .rediscli_historydrwx------.  2 root root  4096 12月 31 18:59 .ssh-rw-r--r--.  1 root root   129 12月  4 2004 .tcshrc-rw-------.  1 root root  5190 12月 31 18:18 .viminfo-rw-------.  1 root root    57 12月 10 21:54 .xauthAy9Cwu[[email protected] ~]# cd .ssh[[email protected] .ssh]# ls -l總用量 12-rw-------. 1 root root 1743 12月 31 18:59 id_rsa-rw-r--r--. 1 root root  405 12月 31 18:59 id_rsa.pub-rw-r--r--. 1 root root 1184 12月 29 17:10 known_hosts

[[email protected] .ssh]# cat id_rsa.pub
  ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyzSZ+5GNn98KxUkEthl4dg8knuTb8znI/oyZ6kzuObZ7AoOd2T/fJVirHE7FKq0nw5zwUF1xez0F8SEgMzQJuXECmEo86DWaYY+Qhh7KSdw30E8g   GVMcJvTbMBbQx/tmb9NrjT44STe+sg6HbW8keFxS8VnpJJww26RhGaZzQz30lA55mNF7H7ELfG9pyApNs9iFZFWGf7T/OWQtDQ5v0quNoW3xqBfn0eMHYe0ebZGnIfLumBE8DZAuxOqK6FHw== j a  [email protected]@qq.com
[[email protected] .ssh]# ssh -T [email protected]

3、在github自己帳號上輸入公開金鑰

4、驗證串連github的jacky-lulu帳號的公開金鑰是否可行

ssh -T [email protected]The authenticity of host ‘github.com (192.30.253.112)‘ can‘t be established.RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added ‘github.com,192.30.253.112‘ (RSA) to the list of known hosts.Enter passphrase for key ‘/root/.ssh/id_rsa‘: Hi jacky-lulu! You‘ve successfully authenticated, but GitHub does not provide shell access.

5、進入的本地倉庫的工程,建立與github的jacky-lulu的串連

[[email protected] home]# cd git_project[[email protected] git_project]# ls -l總用量 8-rw-r--r--. 1 root root 28 12月 31 18:32 1.java-rw-r--r--. 1 root root 80 12月 31 18:32 2.java[[email protected] git_project]# ls1.java  2.java[[email protected] git_project]# git remote add origin https://github.com/jacky-lulu/git_project.git[[email protected] git_project]# git remoteorigin[[email protected] git_project]# git remote -vorigin    https://github.com/jacky-lulu/git_project.git (fetch)       #從github下載工程的串連origin    https://github.com/jacky-lulu/git_project.git (push)        #往github上傳工程的串連

6、首先在github上建立一個新工程,名稱叫git_project(與本地工程名稱同名)

7、往github上push工程git_project

[[email protected] git_project]# git push -u origin master      #表示把當前master分支push到github上(gnome-ssh-askpass:15702): Gtk-WARNING **: cannot open display: error: unable to read askpass response from ‘/usr/libexec/openssh/gnome-ssh-askpass‘Username for ‘https://github.com‘: jacky-lulu               #輸入帳號名稱(gnome-ssh-askpass:15708): Gtk-WARNING **: cannot open display: error: unable to read askpass response from ‘/usr/libexec/openssh/gnome-ssh-askpass‘Password for ‘https://[email protected]‘:               #輸入密碼對象計數中: 26, 完成.壓縮對象中: 100% (19/19), 完成.寫入對象中: 100% (26/26), 2.02 KiB | 0 bytes/s, 完成.Total 26 (delta 2), reused 0 (delta 0)remote: Resolving deltas: 100% (2/2), done.To https://github.com/jacky-lulu/git_project.git * [new branch]      master -> master分支 master 設定為跟蹤來自 origin 的遠程分支 master。

8、故意在github上修改工程git_project工程的2.java檔案在同步到本地

[[email protected] git_project]# git fetch origin    #把gitgub遠端倉庫同步到緩衝區remote: Counting objects: 3, done.remote: Compressing objects: 100% (3/3), done.remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0展開對象中: 100% (3/3), 完成.來自 https://github.com/jacky-lulu/git_project   c1f3cea..0c2df23  master     -> origin/master[[email protected] git_project]# ls1.java  2.java[[email protected] git_project]# cat 2.javamaster 2master 3master 4branch jacky1master jacky222branch jacky222222222[[email protected] git_project]# git merge origin/master    #把緩衝區的合并到本地庫的master分支上更新 c1f3cea..0c2df23Fast-forward 2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)[[email protected] git_project]# cat 2.javamaster 2master 3master 4branch jacky1master jacky222branch jacky222222222遠程倉庫修改內容22222222222222222222222222222222222222222222    #同步成功

 

把本地倉庫工程上傳到github上和從gitbu同步工程到本地

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.