|
1 | | -# Git Profile switcher |
| 1 | +# Git Profile |
2 | 2 |
|
3 | 3 | [](https://github.com/dotzero/git-profile/actions/workflows/ci.yml) |
4 | 4 | [](https://github.com/dotzero/git-profile/blob/master/LICENSE) |
5 | 5 |
|
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. |
7 | 7 |
|
8 | 8 |  |
9 | 9 |
|
10 | 10 | ## Installation |
11 | 11 |
|
12 | | -If you are a macOS user, you can use [Homebrew](http://brew.sh/): |
| 12 | +### Homebrew |
13 | 13 |
|
14 | 14 | ```bash |
15 | 15 | brew install dotzero/tap/git-profile |
16 | 16 | ``` |
17 | 17 |
|
18 | 18 | ### Prebuilt binaries |
19 | 19 |
|
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`. |
21 | 21 |
|
22 | | -### Building from source |
| 22 | +### Build from source |
23 | 23 |
|
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: |
25 | 33 |
|
26 | 34 | ```bash |
27 | | -go get -u github.com/dotzero/git-profile |
| 35 | +git-profile add |
28 | 36 | ``` |
29 | 37 |
|
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 | +``` |
31 | 43 |
|
32 | 44 | ## Usage |
33 | 45 |
|
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: |
35 | 49 |
|
36 | 50 | ```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 |
40 | 54 | ``` |
41 | 55 |
|
42 | | -If no arguments are provided, `add` starts an interactive mode: |
| 56 | +Run without arguments to start interactive mode: |
43 | 57 |
|
44 | 58 | ```bash |
45 | | -git profile add |
| 59 | +git-profile add |
46 | 60 | ``` |
47 | 61 |
|
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. |
52 | 70 |
|
53 | | -Displays a list of available profiles |
| 71 | +### `list` |
| 72 | + |
| 73 | +Show all available profiles: |
54 | 74 |
|
55 | 75 | ```bash |
56 | | -git profile list |
| 76 | +git-profile list |
57 | 77 | ``` |
58 | 78 |
|
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: |
60 | 82 |
|
61 | 83 | ```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 |
65 | 87 | ``` |
66 | 88 |
|
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` |
69 | 93 |
|
70 | | -Applies the selected profile entries to the current git repository |
| 94 | +Apply a profile to the current Git repository: |
71 | 95 |
|
72 | 96 | ```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: |
74 | 101 |
|
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 |
79 | 106 | ``` |
80 | 107 |
|
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: |
82 | 109 |
|
83 | 110 | ```bash |
84 | | -git profile use |
| 111 | +git-profile use |
85 | 112 | ``` |
86 | 113 |
|
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: |
88 | 119 |
|
89 | 120 | ```bash |
90 | | -git profile export home > home.json |
| 121 | +git-profile current |
91 | 122 | ``` |
92 | 123 |
|
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: |
94 | 129 |
|
95 | 130 | ```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 |
97 | 171 | ``` |
98 | 172 |
|
99 | 173 | ## Shell Completion |
100 | 174 |
|
101 | | -Shell completion is available for `git-profile` command. |
| 175 | +Shell completion is available for `git-profile`. |
102 | 176 |
|
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. |
104 | 178 |
|
105 | 179 | ### Bash |
106 | 180 |
|
107 | 181 | Requires [bash-completion](https://github.com/scop/bash-completion). |
108 | 182 |
|
109 | 183 | ```bash |
110 | | -# Temporary (current session only) |
111 | 184 | source <(git-profile completion bash) |
| 185 | +``` |
112 | 186 |
|
113 | | -# Permanent (Linux) |
| 187 | +To install permanently: |
| 188 | + |
| 189 | +```bash |
114 | 190 | git-profile completion bash | sudo tee /etc/bash_completion.d/git-profile |
| 191 | +``` |
115 | 192 |
|
116 | | -# Permanent (macOS) |
| 193 | +On macOS: |
| 194 | + |
| 195 | +```bash |
117 | 196 | git-profile completion bash > $(brew --prefix)/etc/bash_completion.d/git-profile |
118 | 197 | ``` |
119 | 198 |
|
120 | 199 | ### Zsh |
121 | 200 |
|
122 | 201 | ```bash |
123 | | -# Create completion directory if it doesn't exist |
124 | 202 | mkdir -p ~/.zsh/completions |
125 | | - |
126 | | -# Generate completion file |
127 | 203 | git-profile completion zsh > ~/.zsh/completions/_git-profile |
128 | | - |
129 | | -# Add to ~/.zshrc if not already present |
130 | 204 | echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc |
131 | | -echo "autoload -U compinit && compinit" >> ~/.zshrc |
132 | | - |
133 | | -# Reload shell |
| 205 | +echo 'autoload -U compinit && compinit' >> ~/.zshrc |
134 | 206 | source ~/.zshrc |
135 | 207 | ``` |
136 | 208 |
|
137 | 209 | ### Fish |
138 | 210 |
|
139 | 211 | ```bash |
140 | | -# Temporary (current session only) |
141 | 212 | git-profile completion fish | source |
142 | | - |
143 | | -# Permanent |
144 | 213 | git-profile completion fish > ~/.config/fish/completions/git-profile.fish |
145 | 214 | ``` |
146 | 215 |
|
147 | 216 | ## License |
148 | 217 |
|
149 | | -http://www.opensource.org/licenses/mit-license.php |
| 218 | +[MIT](http://www.opensource.org/licenses/mit-license.php) |
0 commit comments