Git & github 最常用操作笔记

  1. 基本配置

     git config --global user.name "foobar"		
     git config --global user.email "foo@bar.com"	
     git config --global core.editor vim		
     git config --global color.ui true
     git config --global merge.tool vimdiff
    

    查看已有配置信息可用 git config --list

  2. 开始使用git

    到项目所在的目录,执行 git init

  3. 添加与提交文件

     git add *.c
     git commit -m "first commit"
    
  4. 生成SSH密钥过程(用于连接github)

    1. 查看是否已经有了ssh密钥:

       cd ~/.ssh
      

      如果没有密钥则不会有此文件夹,有则备份删除

    2. 生成密钥:

       ssh-keygen -t rsa -C "foo@bar.com"
      

      最后得到了两个文件:id_rsa和id_rsa.pub

    3. 登录github,添加 id_rsa.pub 里面的公钥。

    4. 测试:ssh git@github.com

      The authenticity of host ‘github.com (207.97.227.239)’ 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,207.97.227.239′ (RSA) to the list of known hosts.

      ERROR: Hi tekkub! You’ve successfully authenticated, but GitHub does not provide shell access

      Connection to github.com closed.

  5. 本地已有代码,推送到一个远程仓库上

     git remote add origin https://github.com/foo/bar.git
     git push -u origin master     
    
  6. 克隆一个远程仓库

     git clone git@github.com:billyanyteen/github-services.git
    
  7. 将本地repo与远程的origin的repo合并

    推送本地更新到远程仓库

     git push -u origin master
    

    远程仓库更新到本地

     git pull origin master
原文地址:https://www.cnblogs.com/nettee/p/4101774.html