Skip to content

Commit 4d65031

Browse files
committed
Update README.md
1 parent 408cf6c commit 4d65031

1 file changed

Lines changed: 124 additions & 55 deletions

File tree

README.md

Lines changed: 124 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,218 @@
1-
# Git Profile switcher
1+
# Git Profile
22

33
[![build](https://github.com/dotzero/git-profile/actions/workflows/ci.yml/badge.svg)](https://github.com/dotzero/git-profile/actions/workflows/ci.yml)
44
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/dotzero/git-profile/blob/master/LICENSE)
55

6-
Git Profile allows you to switch between multiple user profiles in git repositories
6+
Git Profile helps you manage multiple Git identities and switch between them per repository.
77

88
![](./demo/demo.gif)
99

1010
## Installation
1111

12-
If you are a macOS user, you can use [Homebrew](http://brew.sh/):
12+
### Homebrew
1313

1414
```bash
1515
brew install dotzero/tap/git-profile
1616
```
1717

1818
### Prebuilt binaries
1919

20-
Download the binary from the [releases](https://github.com/dotzero/git-profile/releases) page and place it under `$PATH` directory.
20+
Download a binary from the [releases](https://github.com/dotzero/git-profile/releases) page and place it in a directory listed in `$PATH`.
2121

22-
### Building from source
22+
### Build from source
2323

24-
If your operating system does not have a binary release, but does run Go, you can build it from the source.
24+
```bash
25+
go install github.com/dotzero/git-profile@latest
26+
```
27+
28+
The binary will be installed to `$GOBIN` or `$GOPATH/bin`.
29+
30+
## Quick start
31+
32+
Create a profile:
2533

2634
```bash
27-
go get -u github.com/dotzero/git-profile
35+
git-profile add
2836
```
2937

30-
The binary will then be installed to `$GOPATH/bin` (or your `$GOBIN`).
38+
Apply a profile in the current Git repository:
39+
40+
```bash
41+
git-profile use work
42+
```
3143

3244
## Usage
3345

34-
Adds an entry to a profile or updates an existing profile
46+
### `add`
47+
48+
Add a key to a profile or update an existing one:
3549

3650
```bash
37-
git profile add home user.name dotzero
38-
git profile add home user.email "mail@mail.com"
39-
git profile add home user.signingkey AAAAAAAA
51+
git-profile add work user.name "John Doe"
52+
git-profile add work user.email work@example.com
53+
git-profile add work user.signingkey AAAAAAAA
4054
```
4155

42-
If no arguments are provided, `add` starts an interactive mode:
56+
Run without arguments to start interactive mode:
4357

4458
```bash
45-
git profile add
59+
git-profile add
4660
```
4761

48-
It will ask for the profile name and values for `user.name`, `user.email`, and
49-
`user.signingkey`. Leaving a field empty skips writing that field for a new
50-
profile. For an existing profile, the current values are prefilled and pressing
51-
Enter keeps them unchanged. Press `Esc` or `Ctrl+C` to cancel interactive mode.
62+
Interactive mode asks for:
63+
- profile name
64+
- `user.name`
65+
- `user.email`
66+
- `user.signingkey`
67+
68+
For an existing profile, current values are prefilled.
69+
For a new profile, empty fields are skipped.
5270

53-
Displays a list of available profiles
71+
### `list`
72+
73+
Show all available profiles:
5474

5575
```bash
56-
git profile list
76+
git-profile list
5777
```
5878

59-
Delete a profile or a specific key from a profile
79+
### `del`
80+
81+
Delete a profile or a specific key from a profile:
6082

6183
```bash
62-
git profile del
63-
git profile del home
64-
git profile del home user.email
84+
git-profile del
85+
git-profile del work
86+
git-profile del work user.email
6587
```
6688

67-
When called without arguments, `del` opens an interactive profile selector and
68-
removes the selected profile entirely.
89+
When called without arguments, `del` opens an interactive profile selector and deletes the selected profile.
90+
Press `Esc` or `Ctrl+C` to cancel.
91+
92+
### `use`
6993

70-
Applies the selected profile entries to the current git repository
94+
Apply a profile to the current Git repository:
7195

7296
```bash
73-
git profile use home
97+
git-profile use work
98+
```
99+
100+
Under the hood, this writes local Git config values, for example:
74101

75-
# Under the hood it runs following commands:
76-
# git config --local user.name dotzero
77-
# git config --local user.email "me@dotzero.ru"
78-
# git config --local user.signingkey AAAAAAAA
102+
```bash
103+
git config --local user.name "John Doe"
104+
git config --local user.email work@example.com
105+
git config --local user.signingkey AAAAAAAA
79106
```
80107

81-
If no profile name is provided, an interactive selector will appear to choose a profile
108+
Run without arguments to select a profile interactively:
82109

83110
```bash
84-
git profile use
111+
git-profile use
85112
```
86113

87-
Export a profile in JSON format
114+
`use` must be executed inside a Git repository.
115+
116+
### `current`
117+
118+
Show the currently selected profile for the current repository:
88119

89120
```bash
90-
git profile export home > home.json
121+
git-profile current
91122
```
92123

93-
Import profile from JSON format
124+
If no profile has been applied yet, the command prints `default`.
125+
126+
### `export`
127+
128+
Export a profile as JSON:
94129

95130
```bash
96-
cat home.json | xargs -0 git profile import home
131+
git-profile export work
132+
git-profile export work > work.json
133+
```
134+
135+
Example output:
136+
137+
```json
138+
[
139+
{ "key": "user.name", "value": "John Doe" },
140+
{ "key": "user.email", "value": "work@example.com" },
141+
{ "key": "user.signingkey", "value": "AAAAAAAA" }
142+
]
143+
```
144+
145+
### `import`
146+
147+
Import a profile from JSON:
148+
149+
```bash
150+
git-profile import work '[{"key":"user.name","value":"John Doe"},{"key":"user.email","value":"work@example.com"}]'
151+
```
152+
153+
If you already have JSON in a file:
154+
155+
```bash
156+
git-profile import work "$(cat work.json)"
157+
```
158+
159+
## Config file
160+
161+
By default, Git Profile stores profiles in:
162+
163+
```bash
164+
~/.gitprofile
165+
```
166+
167+
You can override it with:
168+
169+
```bash
170+
git-profile --config /path/to/file add work user.email work@example.com
97171
```
98172

99173
## Shell Completion
100174

101-
Shell completion is available for `git-profile` command.
175+
Shell completion is available for `git-profile`.
102176

103-
**Note:** Use `git-profile TAB` instead of `git profile TAB` for completion.
177+
Note: use `git-profile ...`, not `git profile ...`, when generating or using completion.
104178

105179
### Bash
106180

107181
Requires [bash-completion](https://github.com/scop/bash-completion).
108182

109183
```bash
110-
# Temporary (current session only)
111184
source <(git-profile completion bash)
185+
```
112186

113-
# Permanent (Linux)
187+
To install permanently:
188+
189+
```bash
114190
git-profile completion bash | sudo tee /etc/bash_completion.d/git-profile
191+
```
115192

116-
# Permanent (macOS)
193+
On macOS:
194+
195+
```bash
117196
git-profile completion bash > $(brew --prefix)/etc/bash_completion.d/git-profile
118197
```
119198

120199
### Zsh
121200

122201
```bash
123-
# Create completion directory if it doesn't exist
124202
mkdir -p ~/.zsh/completions
125-
126-
# Generate completion file
127203
git-profile completion zsh > ~/.zsh/completions/_git-profile
128-
129-
# Add to ~/.zshrc if not already present
130204
echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc
131-
echo "autoload -U compinit && compinit" >> ~/.zshrc
132-
133-
# Reload shell
205+
echo 'autoload -U compinit && compinit' >> ~/.zshrc
134206
source ~/.zshrc
135207
```
136208

137209
### Fish
138210

139211
```bash
140-
# Temporary (current session only)
141212
git-profile completion fish | source
142-
143-
# Permanent
144213
git-profile completion fish > ~/.config/fish/completions/git-profile.fish
145214
```
146215

147216
## License
148217

149-
http://www.opensource.org/licenses/mit-license.php
218+
[MIT](http://www.opensource.org/licenses/mit-license.php)

0 commit comments

Comments
 (0)