使用git

使用git命令行对github的仓库进行管理

Posted by Chopong on May 2, 2019

Table of Contents

使用git

使用git命令行对github的仓库进行管理

只使用git

  1. 首先, 你需要设置git配置信息

         # 设置github用户名
         git config --global user.name "yourname"
         # 设置用户邮箱(必须)
         git config --global user.email yourname@example.com
         # 设置编辑器
         git config --global core.editor emacs
         # 设置color, 下同
         git config --global color.status "auto"
         git config --global color.branch "auto"
         git config --global color.interactive "auto"
         git config --global color.diff "auto"
    
  2. 配置信息可以通过命令来查询

         git config --list
         git config user.name
    
  3. 然后, 生成ssh-key, 在~/.ssh/id_rsa.pub找到以rsa开头的文件, 复制粘贴到github上

         ssh-keygen -t rsa -C "yourname@example.com"
    

    登陆github, 点开个人设置, 左侧有GPG, SSHkey添加一栏, 点击添加, 将上述内容粘贴保存即可. 另外, 需要将rsa的权限改为 700 或 600

         chmod 600 -R ~/.ssh/id_rsa
    
  4. 在你想上传的文件夹下, 打开命令行, 输入

         # 初始化仓库
         git init
         # 查看变动状态
         git status
         # 把所有的变动保存
         git add .
         # 提交到本地仓库, 并注释为commit info
         git commit -m 'commit info'
         # 把本地仓库关联到github上, 必须与上面添加的用户名一致, repo为你的仓库名.
         git remote add origin git@github.com:yourname/repo.git
         # 从github上master分支pull下信息到本地仓库origin
         git pull origin master
         # 从本地仓库origin上传push到github上master分支
         git push origin master
    
    

使用git(magit)+emacs

如果你使用emacs, 可以使用magit插件, 非常便捷, 只需要下载magit插件, 并在.emacs文件, 或者init.el文件中, 添加(require ‘magit), 每次上传时, 只用按动快捷键皆可

key command
C-g g git status
s git add
c c git commit 输入注释信息
C-c C-c git commit
P p push到master.

上传成功

参考文章

https://www.cnblogs.com/my-freedom/p/5701427.html