zoukankan      html  css  js  c++  java
  • 把本地仓库工程上传到github上和从gitbu同步工程到本地

    1、在本地产生秘钥和公钥

    [root@jacky git_project]# ssh-keygen -t rsa -C "jacky-lulu@1073740572@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、查看公钥

    [root@jacky /]# cd /root
    [root@jacky ~]# ls -al
    总用量 156
    dr-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 .cshrc
    drwx------.  2 root root  4096 10月  7 09:51 .gconf
    drwx------.  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_history
    drwx------.  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
    [root@jacky ~]# cd .ssh
    [root@jacky .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

    [root@jacky .ssh]# cat id_rsa.pub
      ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyzSZ+5GNn98KxUkEthl4dg8knuTb8znI/oyZ6kzuObZ7AoOd2T/fJVirHE7FKq0nw5zwUF1xez0F8SEgMzQJuXECmEo86DWaYY+Qhh7KSdw30E8g   GVMcJvTbMBbQx/tmb9NrjT44STe+sg6HbW8keFxS8VnpJJww26RhGaZzQz30lA55mNF7H7ELfG9pyApNs9iFZFWGf7T/OWQtDQ5v0quNoW3xqBfn0eMHYe0ebZGnIfLumBE8DZAuxOqK6FHw== j a  cky@1073740572@qq.com
    [root@jacky .ssh]# ssh -T git@github.com

    3、在github自己账号上输入公钥

    4、验证连接github的jacky-lulu账号的公钥是否可行

    ssh -T git@github.com
    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)? yes
    Warning: 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的连接

    [root@jacky home]# cd git_project
    [root@jacky 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
    [root@jacky git_project]# ls
    1.java  2.java
    [root@jacky git_project]# git remote add origin https://github.com/jacky-lulu/git_project.git
    [root@jacky git_project]# git remote
    origin
    [root@jacky git_project]# git remote -v
    origin    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

    [root@jacky 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://jacky-lulu@github.com':               #输入密码
    对象计数中: 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文件在同步到本地

    [root@jacky 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
    [root@jacky git_project]# ls
    1.java  2.java
    [root@jacky git_project]# cat 2.java
    master 2
    master 3
    master 4
    branch jacky1
    master jacky222
    branch jacky222222222
    
    [root@jacky git_project]# git merge origin/master    #把缓冲区的合并到本地库的master分支上
    更新 c1f3cea..0c2df23
    Fast-forward
     2.java | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    [root@jacky git_project]# cat 2.java
    master 2
    master 3
    master 4
    branch jacky1
    master jacky222
    branch jacky222222222
    远程仓库修改内容22222222222222222222222222222222222222222222    #同步成功
  • 相关阅读:
    C++复制构造函数,类型转换构造函数,析构函数,引用,指针常量和常量指针
    POJ1611(The Suspects)--简单并查集
    最小生成树-Kruskal算法
    POJ1861(Network)-Kruskal
    POJ1979(Red and Black)--FloodFill
    [转]全网最!详!细!tarjan算法讲解
    POJ1573(Robot Motion)--简单模拟+简单dfs
    最小生成树-Prim算法
    POJ3368(Frequent values)--线段树
    POJ3255(Roadblocks)--次短路径
  • 原文地址:https://www.cnblogs.com/520playboy/p/6241534.html
Copyright © 2011-2022 走看看