You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/book/10-git-in-other-environments/chapter10.asc
+53-10Lines changed: 53 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,39 +116,80 @@ Visual Studio 2013's Git support is a separate feature with its own command pane
116
116
=== Git in Bash
117
117
118
118
If you're a Bash user, you can tap into some of your shell's features to make your experience with Git a lot friendlier.
119
+
Git actually ships with plugins for several shells, but it's not turned on by default.
119
120
120
-
One way is by enabling tab-completion.
121
-
// TODO
122
-
123
-
To enable the tab-completion plugin, open your +.bashrc+ and add a line like this:
121
+
First, you need to get a copy of the `contrib/completion/git-completion.bash` file out of the Git source code.
122
+
Copy it somewhere handy, like your home directory, and add this to your `.bashrc`:
124
123
124
+
[source,shell]
125
125
-----
126
-
# TODO
126
+
. ~/git-completion.bash
127
127
-----
128
128
129
+
Once that's done, change your directory to a git repository, and type:
130
+
131
+
[source,shell]
132
+
----
133
+
$ git chec<tab>
134
+
----
135
+
136
+
…and Bash will auto-complete to `git checkout`.
137
+
This works with all of Git's subcommands, command-line parameters, and remotes and ref names where appropriate.
138
+
129
139
It's also useful to customize your prompt to show information about the current directory's Git repository.
130
140
This can be as simple or complex as you want, but there are generally a few key pieces of information that most people want, like the current branch, and the status of the working directory.
131
141
To add these to your prompt, just copy the `contrib/completion/git-prompt.sh` file from Git's source repository to your home directory, add something like this to your +.bashrc+:
132
142
143
+
[source,shell]
133
144
-----
134
145
. ~/git-prompt.sh
135
146
export GIT_PS1_SHOWDIRTYSTATE=1
136
147
export PS1='\w$(__git_ps1 " (%s)")\$ '
137
148
-----
138
149
139
-
This makes your shell prompt look like <<git_bash>> when you're anywhere inside a Git-controlled project.
150
+
The `\w` means print the current working directory, the `\$` prints the `$` part of the prompt, and `__git_ps1 " (%s)"` calls the function provided by `git-prompt.sh` with a formatting argument.
151
+
Now your bash prompt will look like <<git_bash>> when you're anywhere inside a Git-controlled project.
Both of these scripts come with helpful documentation; take a look at the contents of `git-completion.bash` and `git-prompt.sh` for more information.
158
+
145
159
=== Git in Zsh
146
160
147
-
If you're a Zsh user, TODO
161
+
Git also ships with a tab-completion library for Zsh.
162
+
Just copy `contrib/completion/git-completion.zsh` to your home directory and source it from your `.zshrc`.
163
+
Zsh's interface is a bit more powerful than Bash's:
164
+
165
+
[source,shell]
166
+
----
167
+
$ git che<tab>
168
+
check-attr -- display gitattributes information
169
+
check-ref-format -- ensure that a reference name is well formed
170
+
checkout -- checkout branch or paths to working tree
171
+
checkout-index -- copy files from index to working directory
172
+
cherry -- find commits not merged upstream
173
+
cherry-pick -- apply changes introduced by some existing commits
174
+
----
175
+
176
+
Ambiguous tab-completions aren't just listed.
177
+
They have helpful descriptions, and you can graphically navigate the list by repeatedly hitting tab.
178
+
This works with Git commands, their arguments, and names of things inside the repository (like refs and remotes), as well filenames and all the other things Zsh knows how to tab-complete.
179
+
180
+
Zsh happens to be fairly compatible with Bash when it comes to prompt customization, but it allows you to have a right-side prompt as well.
181
+
To include the branch name on the right side, add these lines to your `~/.zshrc` file:
182
+
183
+
[source,shell]
184
+
----
185
+
setopt prompt_subst
186
+
. ~/git-prompt.sh
187
+
export RPROMPT=$'$(__git_ps1 "%s")'
188
+
----
189
+
190
+
This results in TODO
148
191
149
-
* tab completion in the box?
150
-
* raw zsh custom prompt
151
-
* oh-my-zsh, themes
192
+
TODO: oh-my-zsh, themes
152
193
153
194
=== Git in Powershell
154
195
@@ -161,12 +202,14 @@ image::images/git-posh.png[Powershell with Posh-git.]
161
202
162
203
If you've installed GitHub for Windows, Posh-Git is included by default, and all you have to do is add these lines to your +profile.ps1+ (which is usually located in +C:\Users\<username>\Documents\WindowsPowerShell+):
163
204
205
+
[source,powershell]
164
206
-----
165
207
# TODO
166
208
-----
167
209
168
210
If you're not a GitHub for Windows user, just download a Posh-Git release from (TODO: URL), uncompress it to the +WindowsPowershell+ directory, and add this to your +profile.ps1+:
0 commit comments