站内链接:

Install at Linux

注意: key 仅仅适用于 git 路径.

Install

1
2
# Ubuntu
sudo apt-get install git

Environment Variables

建议: git config –help

List:

1
2
3
4
# 查看所有的可配置项
git config --list
# 获取远程信息
git remote show origin

User and Email: 用于设置提交代码时的默认用户名/邮箱.

1
2
3
4
5
6
7
8
9
# global
git config --system user.name "unlessbamboo"
git config --system user.email "unlessbamboo@gmail.com"
# user
git config --global user.name "unlessbamboo"
git config --global user.email "unlessbamboo@gmail.com"
# directory
git config user.name "unlessbamboo"
git config user.email "unlessbamboo@gmail.com"

Color:

1
2
3
4
5
# 所有的终端默认着色
git config --global color.ui true
# 状态输出的颜色配置
git config --global color.status auto
git config --global color.branch auto

Editor:

1
2
# 设置默认编辑器, 在git -m时默认调用该路径的程序
git config --global core.editor /usr/bin/vim

Configure File Location

1
2
3
4
5
6
# 所有用户共用,通过git config --system 来设置
/etc/gitconfig:
# 当前用户共用,通过git config --global来设置
~/.gitconfig:
# 当前repository独有
.git/config:

例如~/.gitconfig 的配置如下:

1
2
3
4
5
6
7
8
9
10
11
# This is Git's per-user configuration file.
[user]
name = unlessbamboo
email = unlessbamboo@gmail.com
# Please adapt and uncomment the following lines:
# name = bamboo
# email = bamboo@bamboodeMacBook-Air.local
[credential]
helper = osxkeychain
[core]
excludesfile = ~/.gitignore

Install at Windows

Install

git 安装的时候可以选择类 UNIX 的操作,之后启动 git 命令行时某些操作类似 shell。

PS:注意,Git-2.9.2-64-bit.exe 版本无需再设置 git 的路径,但是必须使用内置的终端启动 git 的命令行。

Configure

PS:git 自带的命令行操作和 Linux 上的操作其实一模一样。

User and Password:

1
2
3
# 用户名和密码, 此时会在C:\Users\bamboo目录下面生成.gitconfig文件
git config --global user.name "unlessbamboo"
git config --global user.email "unlessbamboo@gmail.com"

Key:

1
2
3
# 实际目录: C:\Users\bamboo\.ssh
cd ~/.ssh
ssh-keygen -t rsa -C "unlessbamboo@gmail.com"

Git Export

basic

导出 git 项目下的原始内容,不包含版本控制信息,export git project, use archive command.

1
2
3
4
5
6
7
8
# Chapter 1 -- archive to special directory
git archive master | tar -x -C ~/Downloads/

# Chapter 2 -- ZIP archive
git archive --format zip --output /full/path/to/zipfile.zip master

# Chapter 3 -- checkout current branch
git checkout-index -a -f --prefix=/Users/bamboo/Public/devproject/django-bamboo-polls/

Summary

统计 git export 过程中的信息: git export –sumary

Ignore

Syntax

1
2
3
4
5
6
7
/:     表示递归, 其中build/表示忽略build文件夹
!: 表示否定忽略, 例如!a.py表示该文件不会被忽略
*: 表示0~N 字符
[]: 表示括号内的任意字符
?: 表示单个字符
\: 表示转移字符
**: 表示任何地方的多层级目录, 例如**/foo(匹配foo, foo/bar), abc/**(匹配abc下级的所有文件), a/**/b(匹配a/b, a/x/b, a/x/y/b)

Global ignore

默认配置:/.gitignore_global
手动配置全局:git config –global core.excludesfile ‘
/.gitignore’

Ignore File

1
2
3
4
5
6
# 忽略特定文件(所有成员共享,.gitignore)
.gitignore
# 本地忽略文件
.git/info/exclude
# 追踪空文件
.gitkeep,之后会自动追踪空文件夹

Ignore local change(在版本控制中的文件)

1
2
3
4
# 对特定的文件忽略本地修改(ignore the content change.)
git update-index --assume-unchanged [<file> …]
# 重置
git update-index --no-assume-unchanged [<file> ...]

Ignore untrack file

自动的获取当前本地仓库中的 untrack file, 并自动加入到 gitignore 中

1
echo "$(git status --porcelain | grep '^??' | cut -c4-)" >> .gitignore

Alias

另见oh-my-zsh说明.
见~/.oh-my-zsh/plugins/git/git.plugin.zsh 文件说明

Command

Command :git config –global -e 或者 直接编写~/.gitconfig 文件.

Configure

1
2
[alias]
st = status

Advinse

建议直接使用 bash 的 alias 功能, 默认情况下, .on-my-zsh/plugins/git/git.plugin.zsh 中就存在一份非常完美的”别名命令”.

Test

参考 ssh 命令说明:
Note: 注意, 仅仅适用于 git 协议, 而非 https 协议, 关于<git 协议>

github

测试是否配置成功

1
2
3
4
# 正常测试
ssh -T git@github.com
# Debug调试
ssh -vvT git@github.com

coding

1
2
3
4
# 正常
ssh -T git@git.coding.net
# DEBUG
ssh -vvT git@git.coding.net

gitlab

1
2
# 测试特定端口
ssh -vvv -T -p 2222 gitlab.myserver.com