快速创建github远程同步

使用于已经存在和新的项目

  1. 对于已经存在的/root/py

[root@centos65 py]# ls

all*2.py               cltostr.py                 error_raise_exception.py            function_generator.py    lambda2.py       re-example-3.py

all*3.py               deco_recur_deco.py         error_test2.py                      function_hide.py         list_format.py   re-example-4.py

all*4.py               deco_test1.py              error_test3.py                      function_test_lambda.py  listresolv1.py   re-split.py

all*5.py               deco_test2.py              error_test4.py                      function_test.py         logendswith.py   rmbfroma.py

all*6.py               deco_test3.py              error_test5.py                      functools_partial.py     map_test1.py     str_format.py

all*7.py               deco_test4.py              error_test.py                       generator2.py            map_test2.py     strtonl.py

all*.py                deco_test5.py              error_try_except_test.py            generator.py             map_test3.py     structtest2.py

apowerb.py             deco_test6.py              error_try_finally.py                generindef1.py           metric1.py       structtest.py

args_test1.py          deco_test8.py              exitfilewrite.py                    hello.py                 name.py          time-example-1.py

args_test.py           ?deco_test9.py             fibo.py                             imple_class_iter.py      nestfunc.py      _translator.py

已经有了这么多文件

2. 现在要把它创建一个github的库

[root@centos65 py]# git init

Initialized empty Git repository in /root/py/.git/

3. 在github上创建一个叫py的repostory,并把产生的ssh域名号'https://github.com/lbs1991/py.git'  copy起来

4. [root@centos65 py]# mkdir /root/.ssh/py

    用来存id_rsa

5. 

[root@centos65 py]# ssh-keygen -C 'https://github.com/lbs1991/py.git' -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/py/id_rsa

Enter passphrase (empty for no passphrase): 

Enter same passphrase again: 

Your identification has been saved in /root/.ssh/py/id_rsa.

Your public key has been saved in /root/.ssh/py/id_rsa.pub.

The key fingerprint is:

4a:ea:49:f6:b5:5a:0a:15:97:b2:70:0a:0a:2d:34:c5 https://github.com/lbs1991/py.git

The key's randomart image is:

+--[ RSA 2048]----+

| oo.             |

|...E     .       |

|o o . + o        |

|.o . + =         |

|.   . + S        |

|     + .         |

|    = . o        |

|   + + + .       |

|    o +..        |

+-----------------+

6. 然后把下面pub文件的内容复制到github上的ADD SSH中(settings里面)

[root@centos65 py]# cd /root/.ssh/py

[root@centos65 py]# ls

id_rsa  id_rsa.pub

[root@centos65 py]# vi id_rsa.pub

7. 测试rsa成功

$ ssh -v [email protected]

8.

[root@centos65 py]# git remote add origin [email protected]:lbs1991/py.git

[root@centos65 py]# git add .   //把当前库里的文件都加到暂存区

[root@centos65 py]# git commit -m 'all files' //合并到分支上

9. 推送到github上

[root@centos65 py]# git push -u origin master

第一次需要-u,以后就不用了。


你可能感兴趣的:(github,linux,git)