Git and Github

没有用过 Git


1. 安装

$ brew install git


$ git --version

$ which git 的输出也应该是 /usr/local/bin/git.

2. 配置

  1. 设置用户名和邮箱:
    $ git config --global "Your Name Here"
    $ git config --global ""
  2. 设定默认的 push 方式:

    $ git config --global push.default simple

    (p.s 如果你搞不清的 simple 和 matching 的区别的话就选这个 )


    $ git config --global push.default matching

注:之后也可以通过 .gitconfig 来查看和修改这些配置。

关于 push 是选择 machting 还是 simple 的官方解释

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

解决 commit 的时候出现的 vi 编辑器的问题

Mac OS 下面 vi 编辑器和 git 一起用的时候会出问题。

error: There was a problem with the editor 'vi'

所以需要设置编辑器为 vim。

$ git config --global core.editor /usr/bin/vim

Advanced Settings

  • 进阶请参见 设置 Git:包括 SSH,HTTPS。

小抄 | Git Cookbook

如何把当前的 branch 设置成 master. 2

git checkout better_branch
git merge --strategy=ours master    # keep the content of this branch, but record a merge
git checkout master
git merge better_branch             # fast-forward master up to the merge


git checkout new-master
git branch -m master old-master
git branch -m new-master master
# And don't do this part.  Just don't.  But if you want to...
# git branch -d --force old-master

如何移除 git上的敏感信息





results matching ""

    No results matching ""