为git仓库设置独立的账户和邮箱

为 git 仓库设置独立的账户和邮箱

0x01 配置 Git 全局默认的账户和邮箱

1
2
3
4
5
6
## 全局默认的用户名和邮箱
$ git config --global user.name "aaa"
$ git config --global user.email "aaa@gmail.com"

## 避免每次git操作都需要输入用户名密码
$ git config --global credential.helper store

0x02 为 git 仓库设置独立的账户和邮箱

使用编辑器打开.git/config文件,直接在文件的最后添加以下信息:

1
2
3
[user]
name = bbb
email = bbb@gmail.com

Windows 上配置 Git SSH

Windows 上配置 Git SSH

https://support.atlassian.com/bitbucket-cloud/docs/set-up-an-ssh-key/

0x01 Set up SSH for Git on Windows

Use this section to create a default identity and SSH key when you’re using Git on Windows. By default, the system adds keys for all identities to the /Users/<username>/.ssh directory.

Step 1. Set up your default identity

From the command line, enter ssh-keygen.

ssh-keygen -t rsa -b 4096 -C "email"

List the contents of .ssh to view the key files.

1
2
$ dir .ssh 
id_rsa id_rsa.pub

Step 2. Add the key to the ssh-agent

If you don’t want to type your password each time you use the key, you’ll need to add it to the ssh-agent.

1
2
$ eval $(ssh-agent) 
$ ssh-add ~/.ssh/id_rsa

20220620153539

Step 3. Add the public key to your Account settings

Open your .ssh/id_rsa.pub file and copy its contents.

From Bitbucket, Paste the copied public key into the SSH Key field. Click Save.

Step 4. Test connection

Return to the command line and verify your configuration and username by entering the following command:

1
$ ssh -T git@bitbucket.org   

0x02 Working with non-default SSH key pair paths

If you used a non-default file path for your GitLab SSH key pair,
you must configure your SSH client to find your GitLab SSH private key
for connections to your GitLab server (perhaps gitlab.com).

For OpenSSH clients this is configured in the ~/.ssh/config file.
Below are two example host configurations using their own key:

1
2
3
4
5
6
7
8
9
# GitLab.com server
Host gitlab.com
RSAAuthentication yes
IdentityFile ~/.ssh/config/private-key-filename-01

# Private GitLab server
Host gitlab.company.com
RSAAuthentication yes
IdentityFile ~/.ssh/config/private-key-filename

0x03 使用ed25519方式生成SSH秘钥

如果使用rsa加密方式,出现秘钥无效,依旧提示输入用户名密码验证,请通过ed25519加密方式,生成ssh秘钥。

ssh-keygen -t ed25519 -C "email" -b 4096

对应生成的私钥 id_ed25519 和公钥 id_ed25519.pub, 其他配置步骤同rsa生成方式一致。

20230726162418

Git手册

Git Hand Book

Git 官方站点: http://git-scm.com/download

0x01 全局 Git 设置

1
2
3
4
5
6
7
8
9
10
11
12
## 用户名和邮箱
$ git config --global user.name "git"
$ git config --global user.email "git@gmail.com"

## 避免每次git操作都需要输入用户名密码
$ git config --global credential.helper store

# 取消ssl认证
$ git config --global http.sslVerify false

## 查看当前配置
$ git config --list

0x02 创建 Git 仓库

1 从远程仓库克隆到本地

1
2
3
$ git clone git://github.com/schacon/grit.git
$ git clone git://github.com/schacon/grit.git mygrit # local path
$ git clone git://github.com/schacon/grit.git mygrit --recursive # 递归拉取子module

2 Create a new repository

1
2
3
4
5
6
$ echo "Git Hand Book" >> README.md
$ git init
$ git add README.md
$ git commit -m "add README"
$ git remote add origin git://github.com/schacon/grit.git
$ git push -u origin master

3 Existing folder

1
2
3
4
5
6
$ cd existing_folder
$ git init
$ git remote add origin git://github.com/schacon/grit.git
$ git add .
$ git commit
$ git push -u origin master

4 Existing Git repository

1
2
3
4
$ cd existing_repo
$ git remote add origin git://github.com/schacon/grit.git
$ git push -u origin --all
$ git push -u origin --tags
阅读更多
Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×