GitHub 笔记

安装 Git

Ubuntu 14.04 LTS

命令行中键入:

sudo apt-get install git

若出现依赖关系,根据提示进行。例如有时会提示「键入 'apt-get -f install'消除依赖问题」。此时记住:只需要在该命令前面加入 sudo 即可(除非你已经以 root 登录,此时不需要加 sudo),install后不需要加任何内容,回车即可。

常用命令

  • 把仓库拉到本地:git clone [URL]
  • 查看仓库状态(修改了哪些文件):git status
  • 提交修改:git add . + git commit -m "message for commit"
  • 切换分支:git checkout [BRANCH NAME]

在 push 时我明明是用自己的 GitHub 用户名登录,为何 GitHub 上显示的不是我登录的 GitHub 账户

例如苹果用户可能会遇到这类问题:push 上去以后,发现 GitHub 显示的结果如下

为什么不是 fengdasuk19?

其实 commit 的时候,(「有时」)会有提示如下:

Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the following command and follow the instructions in your editor to edit your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

git commit --amend --reset-author

注意到第一句话

Your name and email address were configured automatically based on your username and hostname.

由于苹果机用 iCloud 账户登录系统,很显然,默认提交账户被指定为 iCloud 相关账户了。

随后有 2 种方法把提交用户改为 GitHub 账户:

  1. 【方法 1】按照提示,键入第一个命令 git config --global --edit 后,会进入 vi 中修改相应配置文件,按字母键 i 进入「插入」状态,然后在 [user] 下分别修改 name =email =之后的内容为自己 GitHub 账户对应的账户信息。然后再键入 git commit --amend --reset-author 即可。

注意:修改完 nameemail 字段后,检查这两行前面是否有 #,有的话请删除这个 #,否则修改无法生效

  1. 【方法 2】键入 git config --global user.name "你的 GitHub 用户名"git config --global user.email "你的 GitHub 用户名对应的 email 地址"。然后再键入 git commit --amend --reset-author 即可。

如上修改完毕后再 push 到仓库中时,就会发现,commit 信息对应的账户已经变成你的 GitHub 账户了

终于显示出我的账户名了

更新了 GitHub 账户,如何重置本地保存的密码

参考这里,只要在命令行中输入下述命令即可:

git credential-osxkeychain erase

你可能感兴趣的:(GitHub 笔记)