OSX上搭建一個好用的git(hub)環境

Step 1: Install Git html

brew install git bash-completion

Configure things: git

git config --global user.name "cyper"
git config --global user.email "345343747@qq.com"
git config --global alias.co checkout
git config --global apply.whitespace nowarn

Setup an SSH key github

ssh-keygen

Hit return a couple of times -- leave password blank if you want. bash

cat ~/.ssh/id_rsa.pub | pbcopy

Paste that code into your settings page on your repository host(s). app

Get happy Git colors. Paste the following into your~/.gitconfigfile: ssh

[color]
    branch = auto
    diff = auto
    status = auto
[color "branch"]
    current = yellow reverse
    local = yellow
    remote = green
[color "diff"]
    meta = yellow bold
    frag = magenta bold
    old = red bold
    new = green bold
[color "status"]
    added = yellow
    changed = green
    untracked = cyan

Create a~/.gitexcludesfile and paste in this: ide

.DS_Store

There, now you don't have to ignore that every time. this

Bash Fanciness

Add the following to your~/.bash_profileor~/.bashrc: spa

source /usr/local/git/contrib/completion/git-completion.bash
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='[\u@mbp \w$(__git_ps1)]\$ '

That will add tab auto-completion for Git branches, display the current branch on your prompt, and show a '*' after the branch name if there are unstaged changes in the repository, and a '+' if there are staged (but uncommitted) changes. It will look something like this: code

[user@computer ~/Sites/example.com (master*)]$

Bonus

If you want to have a different email address for a particular project (a personal project on your work computer, perhaps?), just run this command inside that project's folder:

git config user.email "you@example.com"

It's the same command as before, this time just omitting the--global.

Sources

相關文章
相關標籤/搜索