· 7 years ago · Oct 09, 2018, 07:18 AM
1## 2. about `config`
2
3You may have more than one git account(one for github and one for work), then you need use different account on different `push` and `pull`. You can config your .bash_profile for a faster account switching here:
4
5- firstly, make sure you've got one ssh keypair, and work properly well communicating with remote git code server.
6- secondly, you generate a new ssh keypair with new user.email using `ssh-keygen` and save this key with different file. Then you've got a second key/user to communicate with git server.
7- `sh-add -l` to list keys you local ssh client keeping. If your new key not in this client, just `ssh-add $secret-key` to add it.
8- third, you add this new pub-key to the github/gitlab settings. Then remote git server know your new key/user. you can clone code with authority.
9- Fouth, config what user you want to use to `git pull/push` on each project. There are two file doing this job, global `~/.gitconfig` and local `.git.config`. I suggest you use your work user as global, which you put it in global file; and side project using this new user, which you can put it in project local `.git/config` file. you can do it quicker and add to bash alias.
10 - `alias gitme='git config user.name "Szymon"; git config user.email shm7@outlook.com'` to config your own github account on this git project(Seeing `./.git/config`file for more info.)
11 - `alias gitwork='git config --global user.name "$workname"; git config --global user.email $workmail'` to config your work account on this project(Seeing `~/.gitconfig` file for more info.)
12
13😀Now you can just use `gitme` and `gitwork` to switch account. And you can check it in ~/.gitconfig.
14
15
16
17- `git config` - Get and set repository or global options
18- `git config --global core.editor vim` set default editor
19- `git config $key $value` set config
20- `git config $key` get config
21- `git config --list` show all config in `$key=$value` list
22- `git help <verb>` , `git <verb> --help` or `man git-<verb>` show static text help