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've read this far, you've learned a lot about how to use Git at the command line.
4
4
You can work with local files, connect your repository to others over a network, and work effectively with others.
5
-
But the story doesn't end there; Git is usually used as part of a larger ecosystem, and the terminal isn't always the best way to work with Git.
6
-
Now we'll take a look at some of the other kinds of environments where Git can be useful.
5
+
But the story doesn't end there; Git is usually used as part of a larger ecosystem, and the terminal isn't always the best way to work with it.
6
+
Now we'll take a look at some of the other kinds of environments where Git can be useful, and how other applications (including yours) work alongside Git.
7
7
8
8
=== Graphical Interfaces
9
9
10
10
Git's native environment is in the terminal.
11
11
New features show up there first, and only at the command line is the full power of Git completely at your disposal.
12
12
But plain text isn't the best choice for all tasks; sometimes a visual representation is what you need, and some users are much more comfortable with a point-and-click interface.
13
13
14
-
Remember that different interfaces are tailored for different workflows.
15
-
Some clients only expose only a carefully curated subset of Git functionality, in order to support a specific way of using Git that the author considers effective.
16
-
When viewed in this light, none of these tools is ``better'' than any of the others, they're simply more fit for their intended purpose.
17
-
Also note that there's nothing these graphical clients can do that the command-line client can't.
14
+
It's important to note that different interfaces are tailored for different workflows.
15
+
Some clients only expose only a carefully curated subset of Git functionality, in order to support a specific way of working that the author considers effective.
16
+
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.
17
+
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.
18
18
19
-
==== gitk & git-gui
19
+
==== +gitk+ and +git-gui+
20
20
21
21
When you install Git, you also get its visual tools, `gitk` and `git-gui`.
22
22
23
-
`gitk` is a graphical shell over `git log`, and it acts primarily as a history viewer.
24
-
It is easiest to invoke from the command-line; `cd` into a Git repository, and type:
23
+
`gitk` is a graphical history viewer.
24
+
Think of it like a powerful GUI shell over +git log+ and +git grep+.
25
+
This is the tool to use when you're trying to find something that happened in the past, or visualize your project's history.
26
+
27
+
Gitk is easiest to invoke from the command-line.
28
+
Just `cd` into a Git repository, and type:
25
29
26
30
-----
27
-
gitk [git log options]
31
+
$ gitk [git log options]
28
32
-----
29
33
30
34
Gitk accepts many command-line options, most of which are passed through to the underlying `git log` action.
@@ -44,7 +48,7 @@ In between is a collection of controls used for searching history.
44
48
It, too, is easiest to invoke from the command line:
45
49
46
50
-----
47
-
git gui
51
+
$ git gui
48
52
-----
49
53
50
54
And it looks something like <<git-gui>>.
@@ -53,28 +57,190 @@ And it looks something like <<git-gui>>.
On the left is the index; unstaged changes are on top, staged changes on the bottom.
61
+
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.
62
+
63
+
At top right is the diff view, which shows the changes for the currently-selected file.
64
+
You can stage individual hunks (or individual lines) by right-clicking in this area.
65
+
66
+
At the bottom right is the message and action area. Type your message into the text box and click ``Commit'' to do something similar to +git commit+.
67
+
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.
68
+
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.
69
+
70
+
+gitk+ and +git-gui+ are examples of task-oriented tools.
71
+
Each of them is tailored for a specific purpose (viewing history and creating commits, respectively), and omit the features not necessary for that task.
72
+
There are several other graphical tools in this category, such as TODO.
73
+
74
+
==== GitHub Desktop
75
+
76
+
77
+
78
+
[[github_win]]
79
+
.GitHub for Windows.
80
+
image::images/github-win.png[GitHub for Windows.]
81
+
82
+
[[github_mac]]
83
+
.GitHub for Mac.
84
+
image::images/github-win.png[GitHub for Mac.]
85
+
86
+
// TODO: wait for Desktop? At least for source-list on Windows.
57
87
58
88
==== Other GUIs
59
89
90
+
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.
91
+
The official Git website has a curated list of the most popular clients at http://git-scm.com/downloads/guis[].
92
+
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[].
93
+
60
94
=== Git in Visual Studio
61
95
96
+
Starting with Visual Studio 2013 Update 1, Visual Studio users have a Git client built directly into their IDE.
97
+
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.
98
+
Visual Studio 2013's Git support is a separate feature with its own command pane, but integrates with your day-to-day work just as well as the older feature.
99
+
100
+
* Commiting
101
+
* diffing
102
+
* history
103
+
* syncing
104
+
* others?
105
+
62
106
=== Git in Eclipse
63
107
108
+
// TODO: Egit
109
+
110
+
* Commiting
111
+
* diffing
112
+
* history
113
+
* syncing
114
+
* others?
115
+
64
116
=== Git in Bash
65
117
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
+
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:
124
+
125
+
-----
126
+
# TODO
127
+
-----
128
+
129
+
It's also useful to customize your prompt to show information about the current directory's Git repository.
130
+
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
+
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
+
133
+
-----
134
+
. ~/git-prompt.sh
135
+
export GIT_PS1_SHOWDIRTYSTATE=1
136
+
export PS1='\w$(__git_ps1 " (%s)")\$ '
137
+
-----
138
+
139
+
This makes your shell prompt look like <<git_bash>> when you're anywhere inside a Git-controlled project.
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.
156
+
A package called Posh-Git (TODO: URL) provides powerful tab-completion facilities, as well as an enhanced prompt to help you stay on top of your repostitory status. It looks like <<git_posh>>.
157
+
158
+
[[git_posh]]
159
+
.Powershell with Posh-git.
160
+
image::images/git-posh.png[Powershell with Posh-git.]
161
+
162
+
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
+
164
+
-----
165
+
# TODO
166
+
-----
167
+
168
+
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+:
169
+
170
+
-----
171
+
# TODO
172
+
-----
173
+
70
174
=== Git in Your Application
71
175
72
-
==== libgit2
176
+
If your application is for developers, chances are good that it could benefit from integration with source control.
177
+
Even other applications, such as document editors, could potentially benefit from version-control features, and Git's model works very well for many different scenarios.
178
+
179
+
Beyond the most trivial use-cases, if you want to make your app work with Git repositories, you have essentially two choices.
180
+
181
+
==== Command-line Git
182
+
183
+
One option is to spawn a shell process and use the Git command-line tool to do the work.
184
+
This has the benefit of being canonical, and all of Git's features are supported.
185
+
This also happens to be fairly easy, as most runtime environments have a relatively simple facility for invoking a process with command-line arguments.
186
+
However, this approach does have some downsides.
187
+
188
+
One is that all the output is in plain text.
189
+
This means that you'll have to parse Git's occasionally-changing output format to read progress and result information, which can be inefficient and error-prone.
190
+
191
+
Another is the lack of error recovery.
192
+
If a repository is corrupted somehow, or the user has a malformed configuration value, Git will simply refuse to perform many operations.
193
+
194
+
Yet another is process management.
195
+
Git requires you to maintain a shell environment on a separate process, which can add unwanted complexity.
196
+
Trying to coordinate many of these processes (especially when potentially accessing the same repository from several processes) can be quite a challenge.
197
+
198
+
==== Libgit2
199
+
200
+
The other option at your disposal is to use Libgit2.
201
+
Libgit2 is a dependency-free implementation of Git, with a focus on having a nice API for use within other programs.
202
+
203
+
Here's what it looks like to read HEAD's commit message with Libgit2:
204
+
205
+
-----
206
+
// TODO
207
+
-----
208
+
209
+
Of course, it isn't very probably that you'll want to write C when using Libgit2.
210
+
Fortunately, there are a number of language-specific bindings available that make it fairly easy to work with Git repositories from your specific language and environment.
211
+
212
+
===== LibGit2Sharp
213
+
214
+
If you're writing a .NET or Mono application, LibGit2Sharp (http://libgit2sharp.github.io/[]) is what you're looking for.
215
+
The bindings are written in C#, and great care has been taken to wrap the raw Libgit2 calls with native-feeling CLR APIs.
216
+
Here's what it looks like to read HEAD's commit message:
217
+
218
+
-----
219
+
// TODO
220
+
-----
221
+
222
+
For desktop Windows applications, there's a NuGet package that will help you get started quickly.
223
+
// TODO: will this work under WinRT? Probably not.
224
+
225
+
===== objective-git
226
+
227
+
If your application is running on an Apple platform, you're likely using Objective C as your implementation language.
228
+
Objective-Git (TODO: URL) is the name of the Libgit2 bindings for that environment.
229
+
Again, here's how to read HEAD's commit message:
230
+
231
+
-----
232
+
// TODO
233
+
-----
234
+
235
+
===== rugged
236
+
237
+
For Ruby programs, Rugged (TODO: URL) is the library to use.
73
238
74
-
==== libgit2sharp
239
+
===== pygit2
75
240
76
-
==== objective-git
241
+
The bindings for Libgit2 in Python are called Pygit2, and can be found at (TODO: URL).
77
242
78
-
==== rugged
243
+
===== Others
79
244
80
-
==== pygit2
245
+
Libgit2 has been bound for a wide variety of programming languages and environments, including C++, Go, Node.js, Erlang, and the JVM.
246
+
The official collection of bindings can be found by browsing the repositories at https://github.com/libgit2/[].
0 commit comments