git command备忘录

全局配置用户名和邮箱:

1
2
git config --global user.name "Alex.Li"
git config --global user.email "Alex.Li@xxxx.com"

ssh密钥生成:

1
ssh-keygen -t rsa -C "Alex.Li@xxxx.com"

储存https/http方式用户名密码:

1
git config --global credential.helper store

添加tag并推送到远端:

1
2
git tag -a 1.0.0 -m 'add version 1.0.0'
git push origin master --tags

更改一个https仓库为ssh仓库:

.git/config

1
url = https://xxxx.com/somebody/abcdef.git

改为

1
url = git@gxxxx.com:somebody/abcdef.git

反之则反

删除remotes/origin/{branch}

远端分支已经删除, 但本地仍可见remotes/origin/{branch}

1
git remote prune origin

repo 操作

对每个子repo进行操作

1
repo forall -vc "git cmd"

i.e.

1
repo forall -vc "git reset --hard"

使用指定private key

1
GIT_SSH_COMMAND='ssh -i private_key.pem -o IdentitiesOnly=yes' git clone git@github.com:codingspirit/iotlab-kvs-jenkins-build.git

修改first commit

1
git rebase -i --root