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
<p>…and Bash will auto-complete to <code>git checkout</code>.
46
+
This works with all of Git’s subcommands, command-line parameters, and remotes and ref names where appropriate.</p>
47
+
</div>
48
+
<divclass="paragraph">
49
+
<p>It’s also useful to customize your prompt to show information about the current directory’s Git repository.
50
+
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.
51
+
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.
62
+
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>EGit comes with plenty of great documentation, which you can find by going to Help > Help Contents, and choosing the "EGit Documentation" node from the contents listing.</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 on a non-Windows platform like Debian.
27
+
A package called Posh-Git (<ahref="https://github.com/dahlbyk/posh-git" class="bare">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/sv/v2/images/posh-git.png" >}}" alt="PowerShell with Posh-git.">
33
+
</div>
34
+
<divclass="title">Figur 165. PowerShell with Posh-git.</div>
<p>Before you’re able to run PowerShell scripts on your machine, you need to set your local ExecutionPolicy to RemoteSigned (Basically anything except Undefined and Restricted). If you choose AllSigned instead of RemoteSigned, also local scripts (your own) need to be digitally signed in order to be executed. With RemoteSigned, only Scripts having the "ZoneIdentifier" set to Internet (were downloaded from the web) need to be signed, others not.
42
+
If you’re an administrator and want to set it for all Users on that machine, use "-Scope LocalMachine".
43
+
If you’re a normal user, without administrative rights, you can use "-Scope CurrentUser" to set it only for you.</p>
44
+
</div>
45
+
<divclass="paragraph">
46
+
<p>More about PowerShell Scopes: <ahref="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes" class="bare">https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes</a></p>
47
+
</div>
48
+
<divclass="paragraph">
49
+
<p>More about PowerShell ExecutionPolicy: <ahref="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy" class="bare">https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy</a></p>
<p>If you have at least PowerShell 5 or PowerShell 4 with PackageManagement installed, you can use the package manager to fetch Posh-Git for you.</p>
61
+
</div>
62
+
<divclass="paragraph">
63
+
<p>More information about PowerShell Gallery: <ahref="https://docs.microsoft.com/en-us/powershell/gallery/overview" class="bare">https://docs.microsoft.com/en-us/powershell/gallery/overview</a></p>
<p>If you want to install Posh-Git only for the current user and not globally, use "-Scope CurrentUser" instead.
74
+
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, posh-git needs to be imported. To do this automatically, include the import statement into you $profile script. This script is executed everytime you open a new PowerShell prompt.
90
+
Keep in mind, that there are multiple $profile scripts. 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" class="bare">https://github.com/dahlbyk/posh-git</a>), and uncompress it to the <code>WindowsPowerShell</code> directory.
103
+
Then open a PowerShell prompt as an administrator, and do this:</p>
104
+
</div>
105
+
<divclass="listingblock">
106
+
<divclass="content">
107
+
<preclass="highlight"><codeclass="language-powershell" data-lang="powershell">> cd ~\Documents\WindowsPowerShell\Module\posh-git
108
+
> .\install.ps1</code></pre>
109
+
</div>
110
+
</div>
111
+
<divclass="paragraph">
112
+
<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 your prompt.</p>
<h2id="_git_in_visual_studio">Git in Visual Studio</h2>
22
+
<divclass="paragraph">
23
+
<p>
24
+
Starting with Visual Studio 2013 Update 1, Visual Studio users have a Git client built directly into their IDE.
25
+
Visual Studio has had source-control integration features for quite some time, but they were oriented towards centralized, file-locking systems, and Git was not a good match for this workflow.
26
+
Visual Studio 2013’s Git support has been separated from this older feature, and the result is a much better fit between Studio and Git.</p>
27
+
</div>
28
+
<divclass="paragraph">
29
+
<p>To locate the feature, open a project that’s controlled by Git (or just <code>git init</code> an existing project), and select View > Team Explorer from the menu.
30
+
You’ll see the "Connect" view, which looks a bit like this:</p>
31
+
</div>
32
+
<divclass="imageblock">
33
+
<divclass="content">
34
+
<imgsrc="{{< relurl "book/sv/v2/images/vs-1.png" >}}" alt="Connecting to a Git repository from Team Explorer.">
35
+
</div>
36
+
<divclass="title">Figur 159. Connecting to a Git repository from Team Explorer.</div>
37
+
</div>
38
+
<divclass="paragraph">
39
+
<p>Visual Studio remembers all of the projects you’ve opened that are Git-controlled, and they’re available in the list at the bottom.
40
+
If you don’t see the one you want there, click the "Add" link and type in the path to the working directory.
41
+
Double clicking on one of the local Git repositories leads you to the Home view, which looks like <ahref="{{< relurl "book/sv/v2/ch00/vs_home" >}}">The "Home" view for a Git repository in Visual Studio.</a>.
42
+
This is a hub for performing Git actions; when you’re <em>writing</em> code, you’ll probably spend most of your time in the "Changes" view, but when it comes time to pull down changes made by your teammates, you’ll use the "Unsynced Commits" and "Branches" views.</p>
43
+
</div>
44
+
<divid="vs_home" class="imageblock">
45
+
<divclass="content">
46
+
<imgsrc="{{< relurl "book/sv/v2/images/vs-2.png" >}}" alt="The Home view for a Git repository in Visual Studio.">
47
+
</div>
48
+
<divclass="title">Figur 160. The "Home" view for a Git repository in Visual Studio.</div>
49
+
</div>
50
+
<divclass="paragraph">
51
+
<p>Visual Studio now has a powerful task-focused UI for Git.
52
+
It includes a linear history view, a diff viewer, remote commands, and many other capabilities.
53
+
For complete documentation of this feature (which doesn’t fit here), go to <ahref="http://msdn.microsoft.com/en-us/library/hh850437.aspx" class="bare">http://msdn.microsoft.com/en-us/library/hh850437.aspx</a>.</p>
check-ref-format -- ensure that a reference name is well formed
33
+
checkout -- checkout branch or paths to working tree
34
+
checkout-index -- copy files from index to working directory
35
+
cherry -- find commits not merged upstream
36
+
cherry-pick -- apply changes introduced by some existing commits</code></pre>
37
+
</div>
38
+
</div>
39
+
<divclass="paragraph">
40
+
<p>Ambiguous tab-completions aren’t just listed; they have helpful descriptions, and you can graphically navigate the list by repeatedly hitting tab.
41
+
This works with Git commands, their arguments, and names of things inside the repository (like refs and remotes), as well as filenames and all the other things Zsh knows how to tab-complete.</p>
42
+
</div>
43
+
<divclass="paragraph">
44
+
<p>Zsh ships with a framework for getting information from version control systems, called <code>vcs_info</code>.
45
+
To include the branch name in the prompt on the right side, add these lines to your <code>~/.zshrc</code> file:</p>
<p>For more information on vcs_info, check out its documentation
71
+
in the <code>zshcontrib(1)</code> manual page,
72
+
or online at <ahref="http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Version-Control-Information" class="bare">http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Version-Control-Information</a>.</p>
73
+
</div>
74
+
<divclass="paragraph">
75
+
<p>Instead of vcs_info, you might prefer the prompt customization script that ships with Git, called <code>git-prompt.sh</code>; see <ahref="https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh" class="bare">https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh</a> for details.
76
+
<code>git-prompt.sh</code> is compatible with both Bash and Zsh.</p>
77
+
</div>
78
+
<divclass="paragraph">
79
+
<p>Zsh is powerful enough that there are entire frameworks dedicated to making it better.
80
+
One of them is called "oh-my-zsh", and it can be found at <ahref="https://github.com/robbyrussell/oh-my-zsh" class="bare">https://github.com/robbyrussell/oh-my-zsh</a>.
81
+
oh-my-zsh’s plugin system comes with powerful git tab-completion, and it has a variety of prompt "themes", many of which display version-control data.
82
+
<ahref="{{< relurl "book/sv/v2/ch00/oh_my_zsh_git" >}}">An example of an oh-my-zsh theme.</a> is just one example of what can be done with this system.</p>
83
+
</div>
84
+
<divid="oh_my_zsh_git" class="imageblock">
85
+
<divclass="content">
86
+
<imgsrc="{{< relurl "book/sv/v2/images/zsh-oh-my.png" >}}" alt="An example of an oh-my-zsh theme.">
87
+
</div>
88
+
<divclass="title">Figur 164. An example of an oh-my-zsh theme.</div>
0 commit comments