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
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.
25
+
Git actually ships with plugins for several shells, but it’s not turned on by default.</p>
26
+
</div>
27
+
<divclass="paragraph">
28
+
<p>First, you need to get a copy of the completions file from the source code of the Git release you’re using.
29
+
Check your version by typing <code>git version</code>, then use <code>git checkout tags/vX.Y.Z</code>, where <code>vX.Y.Z</code> corresponds to the version of Git you are using.
30
+
Copy the <code>contrib/completion/git-completion.bash</code> file somewhere handy, like your home directory, and add this to your <code>.bashrc</code>:</p>
<p>…and Bash will auto-complete to <code>git checkout</code>.
47
+
This works with all of Git’s subcommands, command-line parameters, and remotes and ref names where appropriate.</p>
48
+
</div>
49
+
<divclass="paragraph">
50
+
<p>It’s also useful to customize your prompt to show information about the current directory’s Git repository.
51
+
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.
52
+
To add these to your prompt, just copy the <code>contrib/completion/git-prompt.sh</code> file from Git’s source repository to your home directory, add something like this to your <code>.bashrc</code>:</p>
<p>The <code>\w</code> means print the current working directory, the <code>\$</code> prints the <code>$</code> part of the prompt, and <code>__git_ps1 " (%s)"</code> calls the function provided by <code>git-prompt.sh</code> with a formatting argument.
63
+
Now your bash prompt will look like this when you’re anywhere inside a Git-controlled project:</p>
<p>Both of these scripts come with helpful documentation; take a look at the contents of <code>git-completion.bash</code> and <code>git-prompt.sh</code> for more information.</p>
<p>JetBrains IDEs (such as IntelliJ IDEA, PyCharm, WebStorm, PhpStorm, RubyMine, and others) ship with a Git Integration plugin.
24
+
It provides a dedicated view in the IDE to work with Git and GitHub Pull Requests.</p>
25
+
</div>
26
+
<divclass="imageblock">
27
+
<divclass="content">
28
+
<imgsrc="{{< relurl "book/ms/v2/images/jb.png" >}}" alt="Version Control ToolWindow in JetBrains IDEs">
29
+
</div>
30
+
<divclass="title">Figure 157. Version Control ToolWindow in JetBrains IDEs</div>
31
+
</div>
32
+
<divclass="paragraph">
33
+
<p>The integration relies on the command-line git client, and requires one to be installed.
34
+
The official documentation is available at <ahref="https://www.jetbrains.com/help/idea/using-git-integration.html" class="bare" target="_blank" rel="noopener">https://www.jetbrains.com/help/idea/using-git-integration.html</a>.</p>
The legacy command-line terminal on Windows (<code>cmd.exe</code>) isn’t really capable of a customized Git experience, but if you’re using PowerShell, you’re in luck.
26
+
This also works if you’re running PowerShell Core on Linux or macOS.
27
+
A package called posh-git (<ahref="https://github.com/dahlbyk/posh-git" class="bare" target="_blank" rel="noopener">https://github.com/dahlbyk/posh-git</a>) provides powerful tab-completion facilities, as well as an enhanced prompt to help you stay on top of your repository status.
28
+
It looks like this:</p>
29
+
</div>
30
+
<divclass="imageblock">
31
+
<divclass="content">
32
+
<imgsrc="{{< relurl "book/ms/v2/images/posh-git.png" >}}" alt="PowerShell with Posh-git">
33
+
</div>
34
+
<divclass="title">Figure 161. PowerShell with Posh-git</div>
<p>Before you’re able to run PowerShell scripts on your machine, you need to set your local <code>ExecutionPolicy</code> to <code>RemoteSigned</code> (basically, anything except <code>Undefined</code> and <code>Restricted</code>).
42
+
If you choose <code>AllSigned</code> instead of <code>RemoteSigned</code>, also local scripts (your own) need to be digitally signed in order to be executed.
43
+
With <code>RemoteSigned</code>, only scripts having the <code>ZoneIdentifier</code> set to <code>Internet</code> (were downloaded from the web) need to be signed, others not.
44
+
If you’re an administrator and want to set it for all users on that machine, use <code>-Scope LocalMachine</code>.
45
+
If you’re a normal user, without administrative rights, you can use <code>-Scope CurrentUser</code> to set it only for you.</p>
46
+
</div>
47
+
<divclass="paragraph">
48
+
<p>More about PowerShell Scopes: <ahref="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes" class="bare" target="_blank" rel="noopener">https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes</a>.</p>
49
+
</div>
50
+
<divclass="paragraph">
51
+
<p>More about PowerShell ExecutionPolicy: <ahref="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy" class="bare" target="_blank" rel="noopener">https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy</a>.</p>
52
+
</div>
53
+
<divclass="paragraph">
54
+
<p>To set the value of <code>ExecutionPolicy</code> to <code>RemoteSigned</code> for all users use the next command:</p>
<p>If you have at least PowerShell 5 or PowerShell 4 with PackageManagement installed, you can use the package manager to install posh-git for you.</p>
66
+
</div>
67
+
<divclass="paragraph">
68
+
<p>More information about PowerShell Gallery: <ahref="https://docs.microsoft.com/en-us/powershell/scripting/gallery/overview" class="bare" target="_blank" rel="noopener">https://docs.microsoft.com/en-us/powershell/scripting/gallery/overview</a>.</p>
> Install-Module posh-git -Scope CurrentUser -AllowPrerelease -Force # Newer beta version with PowerShell Core support</code></pre>
74
+
</div>
75
+
</div>
76
+
<divclass="paragraph">
77
+
<p>If you want to install posh-git for all users, use <code>-Scope AllUsers</code> instead and execute the command from an elevated PowerShell console.
78
+
If the second command fails with an error like <code>Module 'PowerShellGet' was not installed by using Install-Module</code>, you’ll need to run another command first:</p>
<p>To include git information in your prompt, the posh-git module needs to be imported.
94
+
To have posh-git imported every time PowerShell starts, execute the <code>Add-PoshGitToProfile</code> command which will add the import statement into your <code>$profile</code> script.
95
+
This script is executed everytime you open a new PowerShell console.
96
+
Keep in mind, that there are multiple <code>$profile</code> scripts.
97
+
E. g. one for the console and a separate one for the ISE.</p>
<p>Just download a posh-git release from <ahref="https://github.com/dahlbyk/posh-git/releases" class="bare" target="_blank" rel="noopener">https://github.com/dahlbyk/posh-git/releases</a>, and uncompress it.
110
+
Then import the module using the full path to the <code>posh-git.psd1</code> file:</p>
<p>This will add the proper line to your <code>profile.ps1</code> file, and posh-git will be active the next time you open PowerShell.</p>
120
+
</div>
121
+
<divclass="paragraph">
122
+
<p>For a description of the Git status summary information displayed in the prompt see: <ahref="https://github.com/dahlbyk/posh-git/blob/master/README.md#git-status-summary-information" class="bare" target="_blank" rel="noopener">https://github.com/dahlbyk/posh-git/blob/master/README.md#git-status-summary-information</a>
123
+
For more details on how to customize your posh-git prompt see: <ahref="https://github.com/dahlbyk/posh-git/blob/master/README.md#customization-variables" class="bare" target="_blank" rel="noopener">https://github.com/dahlbyk/posh-git/blob/master/README.md#customization-variables</a>.</p>
<h2id="_git_in_sublime_text">Git in Sublime Text</h2>
22
+
<divclass="paragraph">
23
+
<p>From version 3.2 onwards, Sublime Text has git integration in the editor.</p>
24
+
</div>
25
+
<divclass="paragraph">
26
+
<p>The features are:</p>
27
+
</div>
28
+
<divclass="ulist">
29
+
<ul>
30
+
<li>
31
+
<p>The sidebar will show the git status of files and folders with a badge/icon.</p>
32
+
</li>
33
+
<li>
34
+
<p>Files and folders that are in your .gitignore file will be faded out in the sidebar.</p>
35
+
</li>
36
+
<li>
37
+
<p>In the status bar, you can see the current git branch and how many modifications you have made.</p>
38
+
</li>
39
+
<li>
40
+
<p>All changes to a file are now visible via markers in the gutter.</p>
41
+
</li>
42
+
<li>
43
+
<p>You can use part of the Sublime Merge git client functionality from within Sublime Text.
44
+
This requires that Sublime Merge is installed. See: <ahref="https://www.sublimemerge.com/" class="bare" target="_blank" rel="noopener">https://www.sublimemerge.com/</a>.</p>
45
+
</li>
46
+
</ul>
47
+
</div>
48
+
<divclass="paragraph">
49
+
<p>The official documentation for Sublime Text can be found here: <ahref="https://www.sublimetext.com/docs/3/git_integration.html" class="bare" target="_blank" rel="noopener">https://www.sublimetext.com/docs/3/git_integration.html</a>.</p>
<p>The official documentation can be found here: <ahref="https://code.visualstudio.com/Docs/editor/versioncontrol" class="bare" target="_blank" rel="noopener">https://code.visualstudio.com/Docs/editor/versioncontrol</a>.</p>
0 commit comments