130 lines
2.7 KiB
Markdown
130 lines
2.7 KiB
Markdown
# git 配置
|
||
|
||
## 账号配置
|
||
|
||
### 配置密钥
|
||
|
||
按邮箱生成密钥, 可以选择 ed25519 类型。
|
||
|
||
```bash
|
||
ssh-keygen -t rsa -f ~/.ssh/id_rsa_your_custom_name -C "your email"
|
||
ssh-keygen -t ed25519 -C "xxxx" -b 4096
|
||
```
|
||
|
||
添加密钥
|
||
|
||
```bash
|
||
ssh-add ~/.ssh/id_rsa_your_custom_name
|
||
```
|
||
|
||
编辑 `~/.ssh/config` 文件,添加如下内容:
|
||
|
||
```text
|
||
Host github.com
|
||
HostName github.com
|
||
User Your_Custom_name
|
||
IdentityFile ~/.ssh/id_rsa_your_custom_name
|
||
```
|
||
|
||
### 配置单用户
|
||
|
||
cd 到项目的根目录,查看 git 配置:
|
||
|
||
```bash
|
||
git config --list
|
||
```
|
||
|
||
看一下 `user.name` 和 `user.email` 是否和希望上传的账号匹配,否则使用如下命令进行修改:
|
||
|
||
```bash
|
||
git config user.email "your@email.com"
|
||
git config user.name "your name"
|
||
```
|
||
|
||
### 配置多用户
|
||
|
||
File `~/.ssh/config` is also very useful when you have to work with multiple git accounts.
|
||
|
||
```config
|
||
Host github.com
|
||
HostName github.com
|
||
User git
|
||
IdentityFile ~/.ssh/github
|
||
|
||
Host github_as_alice
|
||
HostName github.com
|
||
User git
|
||
IdentityFile ~/.ssh/github_alice
|
||
|
||
Host github_as_bob
|
||
HostName github.com
|
||
User git
|
||
IdentityFile ~/.ssh/github_bob
|
||
```
|
||
|
||
Default `github.com` will work by default.
|
||
|
||
For alice: replace 'git@github.com' with 'git@github\_as\_alice' when you use `git clone` or `git remote add origin`.
|
||
|
||
For bob: replace 'git@github.com' with 'git@github\_as\_bob' when you use `git clone` or `git remote add origin`.
|
||
|
||
## 跨平台提交代码配置
|
||
|
||
在 windows 系统中设置
|
||
|
||
```bash
|
||
git config --global core.autocrlf input
|
||
git config --global core.safecrlf true
|
||
git config --global core.eol lf
|
||
```
|
||
|
||
## 设置编辑器
|
||
|
||
```bash
|
||
git config --global core.editor vim
|
||
git config --global merge.tool vimdiff
|
||
```
|
||
|
||
## 编译高版本 git
|
||
|
||
```bash
|
||
yum -y install zlib-devel curl-devel openssl-devel perl cpio expat-devel gettext-devel openssl zlib autoconf tk perl-ExtUtils-MakeMaker
|
||
```
|
||
|
||
下面的命令将 git 安装到 `/usr/local/bin/` 中,可以自行设置 `--prefix` 项
|
||
|
||
```bash
|
||
cd /path/to/git/source
|
||
./configure --prefix=/usr/local
|
||
make
|
||
make install
|
||
```
|
||
|
||
## 分支开发分支发布
|
||
|
||
提交代码
|
||
|
||
```bash
|
||
git push origin HEAD:refs/for/$(git_current_branch)
|
||
```
|
||
|
||
合并代码
|
||
```bash
|
||
git merge --no-ff origin/master
|
||
```
|
||
|
||
## 简单地在从服务器上拉取代码
|
||
|
||
把代码库放在服务器上,ssh 连接的命令为
|
||
|
||
```bash
|
||
ssh username@host
|
||
```
|
||
|
||
把代码库放在目录 `/path/to/code` 中,客户端可使用下面的命令拉取代码
|
||
|
||
```bash
|
||
git remote add origin ssh://username@host:/path/to/code
|
||
git clone ssh://username@host:/path/to/code
|
||
```
|