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: book/A-git-in-other-environments/sections/bash.asc
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,9 @@ First, you need to get a copy of the `contrib/completion/git-completion.bash` fi
8
8
Copy it somewhere handy, like your home directory, and add this to your `.bashrc`:
9
9
10
10
[source,console]
11
-
-----
11
+
----
12
12
. ~/git-completion.bash
13
-
-----
13
+
----
14
14
15
15
Once that's done, change your directory to a Git repository, and type:
16
16
@@ -27,16 +27,16 @@ This can be as simple or complex as you want, but there are generally a few key
27
27
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`:
28
28
29
29
[source,console]
30
-
-----
30
+
----
31
31
. ~/git-prompt.sh
32
32
export GIT_PS1_SHOWDIRTYSTATE=1
33
33
export PS1='\w$(__git_ps1 " (%s)")\$ '
34
-
-----
34
+
----
35
35
36
36
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.
37
37
Now your bash prompt will look like this when you're anywhere inside a Git-controlled project:
Copy file name to clipboardExpand all lines: book/A-git-in-other-environments/sections/guis.asc
+34-35Lines changed: 34 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ But plain text isn't the best choice for all tasks; sometimes a visual represent
7
7
8
8
It's important to note that different interfaces are tailored for different workflows.
9
9
Some clients expose only a carefully curated subset of Git functionality, in order to support a specific way of working that the author considers effective.
10
-
When viewed in this light, none of these tools can be called ``better'' than any of the others, they're simply more fit for their intended purpose.
10
+
When viewed in this light, none of these tools can be called "`better`" than any of the others, they're simply more fit for their intended purpose.
11
11
Also note that there's nothing these graphical clients can do that the command-line client can't; the command-line is still where you'll have the most power and control when working with your repositories.
12
12
13
13
==== `gitk` and `git-gui`
@@ -31,8 +31,8 @@ Gitk accepts many command-line options, most of which are passed through to the
31
31
Probably one of the most useful is the `--all` flag, which tells gitk to show commits reachable from _any_ ref, not just HEAD.
32
32
Gitk's interface looks like this:
33
33
34
-
.The `gitk` history viewer.
35
-
image::images/gitk.png[The `gitk` history viewer.]
34
+
.The `gitk` history viewer
35
+
image::images/gitk.png[The `gitk` history viewer]
36
36
37
37
On the top is something that looks a bit like the output of `git log --graph`; each dot represents a commit, the lines represent parent relationships, and refs are shown as colored boxes.
38
38
The yellow dot represents HEAD, and the red dot represents changes that are yet to become a commit.
@@ -43,14 +43,14 @@ In between is a collection of controls used for searching history.
43
43
It, too, is easiest to invoke from the command line:
On the left is the index; unstaged changes are on top, staged changes on the bottom.
56
56
You can move entire files between the two states by clicking on their icons, or you can select a file for viewing by clicking on its name.
@@ -59,35 +59,34 @@ At top right is the diff view, which shows the changes for the currently-selecte
59
59
You can stage individual hunks (or individual lines) by right-clicking in this area.
60
60
61
61
At the bottom right is the message and action area.
62
-
Type your message into the text box and click ``Commit'' to do something similar to `git commit`.
63
-
You can also choose to amend the last commit by choosing the ``Amend'' radio button, which will update the ``Staged Changes'' area with the contents of the last commit.
64
-
Then you can simply stage or unstage some changes, alter the commit message, and click ``Commit'' again to replace the old commit with a new one.
62
+
Type your message into the text box and click "`Commit`" to do something similar to `git commit`.
63
+
You can also choose to amend the last commit by choosing the "`Amend`" radio button, which will update the "`Staged Changes`" area with the contents of the last commit.
64
+
Then you can simply stage or unstage some changes, alter the commit message, and click "`Commit`" again to replace the old commit with a new one.
65
65
66
66
`gitk` and `git-gui` are examples of task-oriented tools.
67
67
Each of them is tailored for a specific purpose (viewing history and creating commits, respectively), and omit the features not necessary for that task.
68
68
69
+
==== GitHub for macOS and Windows
69
70
70
-
==== GitHub for Mac and Windows
71
-
72
-
(((GitHub for Mac)))(((GitHub for Windows)))
73
-
GitHub has created two workflow-oriented Git clients: one for Windows, and one for Mac.
71
+
(((GitHub for macOS)))(((GitHub for Windows)))
72
+
GitHub has created two workflow-oriented Git clients: one for Windows, and one for macOS.
74
73
These clients are a good example of workflow-oriented tools – rather than expose _all_ of Git's functionality, they instead focus on a curated set of commonly-used features that work well together.
75
74
They look like this:
76
75
77
-
.GitHub for Mac.
78
-
image::images/github_mac.png[GitHub for Mac.]
76
+
.GitHub for macOS
77
+
image::images/github_mac.png[GitHub for macOS]
79
78
80
-
.GitHub for Windows.
81
-
image::images/github_win.png[GitHub for Windows.]
79
+
.GitHub for Windows
80
+
image::images/github_win.png[GitHub for Windows]
82
81
83
82
They are designed to look and work very much alike, so we'll treat them like a single product in this chapter.
84
-
We won't be doing a detailed rundown of these tools (they have their own documentation), but a quick tour of the ``changes'' view (which is where you'll spend most of your time) is in order.
83
+
We won't be doing a detailed rundown of these tools (they have their own documentation), but a quick tour of the "`changes`" view (which is where you'll spend most of your time) is in order.
85
84
86
-
* On the left is the list of repositories the client is tracking; you can add a repository (either by cloning or attaching locally) by clicking the ``+'' icon at the top of this area.
85
+
* On the left is the list of repositories the client is tracking; you can add a repository (either by cloning or attaching locally) by clicking the "`+`" icon at the top of this area.
87
86
* In the center is a commit-input area, which lets you input a commit message, and select which files should be included.
88
-
(On Windows, the commit history is displayed directly below this; on Mac, it's on a separate tab.)
87
+
On Windows, the commit history is displayed directly below this; on macOS, it's on a separate tab.
89
88
* On the right is a diff view, which shows what's changed in your working directory, or which changes were included in the selected commit.
90
-
* The last thing to notice is the ``Sync'' button at the top-right, which is the primary way you interact over the network.
89
+
* The last thing to notice is the "`Sync`" button at the top-right, which is the primary way you interact over the network.
91
90
92
91
[NOTE]
93
92
====
@@ -97,12 +96,12 @@ While they're designed to highlight GitHub's service and recommended workflow, t
97
96
98
97
===== Installation
99
98
100
-
GitHub for Windows can be downloaded from https://windows.github.com[], and GitHub for Mac from https://mac.github.com[].
99
+
GitHub for Windows can be downloaded from https://windows.github.com[], and GitHub for macOS from https://mac.github.com[].
101
100
When the applications are first run, they walk you through all the first-time Git setup, such as configuring your name and email address, and both set up sane defaults for many common configuration options, such as credential caches and CRLF behavior.
102
101
103
-
Both are ``evergreen'' – updates are downloaded and installed in the background while the applications are open.
102
+
Both are "`evergreen`" – updates are downloaded and installed in the background while the applications are open.
104
103
This helpfully includes a bundled version of Git, which means you probably won't have to worry about manually updating it again.
105
-
On Windows, the client includes a shortcut to launch Powershell with Posh-git, which we'll talk more about later in this chapter.
104
+
On Windows, the client includes a shortcut to launch PowerShell with Posh-git, which we'll talk more about later in this chapter.
106
105
107
106
The next step is to give the tool some repositories to work with.
108
107
The client shows you a list of the repositories you have access to on GitHub, and can clone them in one step.
@@ -111,25 +110,25 @@ If you already have a local repository, just drag its directory from the Finder
111
110
===== Recommended Workflow
112
111
113
112
Once it's installed and configured, you can use the GitHub client for many common Git tasks.
114
-
The intended workflow for this tool is sometimes called the ``GitHub Flow.''
115
-
We cover this in more detail in <<ch06-github#r_github_flow>>, but the general gist is that (a) you'll be committing to a branch, and (b) you'll be syncing up with a remote repository fairly regularly.
113
+
The intended workflow for this tool is sometimes called the "`GitHub Flow.`"
114
+
We cover this in more detail in <<ch06-github#ch06-github_flow>>, but the general gist is that (a) you'll be committing to a branch, and (b) you'll be syncing up with a remote repository fairly regularly.
116
115
117
116
Branch management is one of the areas where the two tools diverge.
118
-
On Mac, there's a button at the top of the window for creating a new branch:
117
+
On macOS, there's a button at the top of the window for creating a new branch:
119
118
120
-
.``Create Branch'' button on Mac.
121
-
image::images/branch_widget_mac.png[``Create Branch'' button on Mac.]
119
+
."`Create Branch`" button on macOS
120
+
image::images/branch_widget_mac.png[“Create Branch” button on macOS]
122
121
123
122
On Windows, this is done by typing the new branch's name in the branch-switching widget:
124
123
125
-
.Creating a branch on Windows.
126
-
image::images/branch_widget_win.png[Creating a branch on Windows.]
124
+
.Creating a branch on Windows
125
+
image::images/branch_widget_win.png[Creating a branch on Windows]
127
126
128
127
Once your branch is created, making new commits is fairly straightforward.
129
128
Make some changes in your working directory, and when you switch to the GitHub client window, it will show you which files changed.
130
-
Enter a commit message, select the files you'd like to include, and click the ``Commit'' button (ctrl-enter or ⌘-enter).
129
+
Enter a commit message, select the files you'd like to include, and click the "`Commit`" button (ctrl-enter or ⌘-enter).
131
130
132
-
The main way you interact with other repositories over the network is through the ``Sync'' feature.
131
+
The main way you interact with other repositories over the network is through the "`Sync`" feature.
133
132
Git internally has separate operations for pushing, fetching, merging, and rebasing, but the GitHub clients collapse all of these into one multi-step feature.
134
133
Here's what happens when you click the Sync button:
135
134
@@ -149,5 +148,5 @@ However, if your workflow is different, or you want more control over how and wh
149
148
==== Other GUIs
150
149
151
150
There are a number of other graphical Git clients, and they run the gamut from specialized, single-purpose tools all the way to apps that try to expose everything Git can do.
152
-
The official Git website has a curated list of the most popular clients at http://git-scm.com/downloads/guis[].
151
+
The official Git website has a curated list of the most popular clients at https://git-scm.com/downloads/guis[].
153
152
A more comprehensive list is available on the Git wiki site, at https://git.wiki.kernel.org/index.php/Interfaces,_frontends,_and_tools#Graphical_Interfaces[].
The standard command-line terminal on Windows (`cmd.exe`) isn't really capable of a customized Git experience, but if you're using Powershell, you're in luck.
7
-
A package called Posh-Git (https://github.com/dahlbyk/posh-git[]) provides powerful tab-completion facilities, as well as an enhanced prompt to help you stay on top of your repository status.
6
+
The legacy command-line terminal on Windows (`cmd.exe`) isn't really capable of a customized Git experience, but if you're using PowerShell, you're in luck.
7
+
This also works if you're running PowerShell Core on Linux or macOS.
8
+
A package called posh-git (https://github.com/dahlbyk/posh-git[]) provides powerful tab-completion facilities, as well as an enhanced prompt to help you stay on top of your repository status.
8
9
It looks like this:
9
10
10
-
.Powershell with Posh-git.
11
-
image::images/posh-git.png[Powershell with Posh-git.]
11
+
.PowerShell with Posh-git
12
+
image::images/posh-git.png[PowerShell with Posh-git]
12
13
13
-
Just download a Posh-Git release from (https://github.com/dahlbyk/posh-git[]), and uncompress it to the `WindowsPowershell` directory.
14
-
Then open a Powershell prompt as the administrator, and do this:
14
+
==== Installation
15
+
16
+
===== Prerequisites (Windows only)
17
+
18
+
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`).
19
+
If you choose `AllSigned` instead of `RemoteSigned`, also local scripts (your own) need to be digitally signed in order to be executed.
20
+
With `RemoteSigned`, only scripts having the `ZoneIdentifier` set to `Internet` (were downloaded from the web) need to be signed, others not.
21
+
If you're an administrator and want to set it for all users on that machine, use `-Scope LocalMachine`.
22
+
If you're a normal user, without administrative rights, you can use `-Scope CurrentUser` to set it only for you.
23
+
24
+
More about PowerShell Scopes: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes[].
25
+
26
+
More about PowerShell ExecutionPolicy: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy[].
27
+
28
+
To set the value of `ExecutionPolicy` to `RemoteSigned` for all users use the next command:
> Install-Module posh-git -Scope CurrentUser -AllowPrerelease -Force # Newer beta version with PowerShell Core support
45
+
----
46
+
47
+
If you want to install posh-git for all users, use `-Scope AllUsers` instead and execute the command from an elevated PowerShell console.
48
+
If the second command fails with an error like `Module 'PowerShellGet' was not installed by using Install-Module`, you'll need to run another command first:
This happens, because the modules that ship with Windows PowerShell are signed with a different publishment certificate.
57
+
58
+
===== Update PowerShell Prompt
59
+
60
+
To include git information in your prompt, the posh-git module needs to be imported.
61
+
To have posh-git imported every time PowerShell starts, execute the `Add-PoshGitToProfile` command which will add the import statement into your `$profile` script.
62
+
This script is executed everytime you open a new PowerShell console.
63
+
Keep in mind, that there are multiple `$profile` scripts.
64
+
E. g. one for the console and a separate one for the ISE.
65
+
66
+
[source,powershell]
67
+
----
68
+
> Import-Module posh-git
69
+
> Add-PoshGitToProfile -AllHosts
70
+
----
71
+
72
+
===== From Source
73
+
74
+
Just download a posh-git release from https://github.com/dahlbyk/posh-git/releases[], and uncompress it.
75
+
Then import the module using the full path to the `posh-git.psd1` file:
This will add the proper line to your `profile.ps1` file, and posh-git will be active the next time you open PowerShell.
22
84
23
-
This will add the proper line to your `profile.ps1` file, and posh-git will be active the next time you open your prompt.
85
+
For a description of the Git status summary information displayed in the prompt see: https://github.com/dahlbyk/posh-git/blob/master/README.md#git-status-summary-information[]
86
+
For more details on how to customize your posh-git prompt see: https://github.com/dahlbyk/posh-git/blob/master/README.md#customization-variables[].
0 commit comments