Wiki source code of Getting Started with Git

Version 214.1 by Bastian Triller on 2013/04/21 14:58

Hide last authors
Kieran Kelleher 202.1 1 {{toc}}{{/toc}}
2
David Avendasora 198.1 3 = Got Git? No? Get Git =
Kieran Kelleher 169.1 4
Kieran Kelleher 202.1 5 * Official Download Site: [[http://git-scm.com/download]]
Kieran Kelleher 135.1 6
Kieran Kelleher 202.1 7 {{info title="Git is included with XCode 4.x"}}
Kieran Kelleher 135.1 8
Kieran Kelleher 202.1 9 XCode 4.x installs a copy of git in /usr/bin/git
Ray Kiddy 175.1 10
Kieran Kelleher 202.1 11 {{/info}}
Kieran Kelleher 135.1 12
Kieran Kelleher 202.1 13 = Learn About Git =
Ray Kiddy 171.1 14
Kieran Kelleher 202.1 15 * Learn the concepts.
16 ** Scott Chacon (of GitHub) Video Intro [[http://www.youtube.com/watch?v=ZDR433b0HJY]]
17 ** [[This>>http://www.eecs.harvard.edu/~~cduan/technical/git/]] is an excellent tutorial on the basic concepts behind Git
18 ** [[Git for Computer Scientists>>http://eagain.net/articles/git-for-computer-scientists/]] gives another good view on the underlying concepts
Bastian Triller 213.1 19 ** [[Git For Ages 4 And Up>>https://lca2013.linux.org.au/wiki/Tutorials/Git_For_Ages_4_And_Up]]: video tutorial ([[mp4>>http://mirror.internode.on.net/pub/linux.conf.au/2013/mp4/Git_For_Ages_4_And_Up.mp4]], [[YouTube>>http://www.youtube.com/watch?v=1ffBJ4sVUb4]])
Kieran Kelleher 202.1 20 * Learn the basics.
jbrook 207.1 21 ** [[Everyday GIT With 20 Commands Or So>>http://schacon.github.com/git/everyday.html]]
Kieran Kelleher 202.1 22 ** [[Free Online Pro Git book>>http://progit.org/book/]]
23 *** There is even a free epub version for your iPad/iPhone [[https://github.s3.amazonaws.com/media/progit.epub]]
24
25 * Get familiar with the reference materials available online
26 ** [[Git Community Book>>http://book.git-scm.com/]]
27 ** Official [[Git Documentation>>http://git-scm.com/documentation]] Site
28 ** Official [[Git User Manual>>http://www.kernel.org/pub/software/scm/git/docs/user-manual.html]]
29 ** [[Git Reference>>http://gitref.org/index.html]]
30
31 * Git Cheat Sheets
32 ** [[http://cheat.errtheblog.com/s/git/]]
33
Kieran Kelleher 165.1 34 * [[Linus Torvalds talks about git>>http://www.youtube.com/watch?v=4XpnKHJAok8]]
Kieran Kelleher 202.1 35 Have a Good Laugh here as Linus Torvalds Evangelizes git. //NOTE: This isn't really learning, but it is way more fun and gives you insight into the motivation behind git.//
Kieran Kelleher 165.1 36
Kieran Kelleher 202.1 37 = Get Started with Project Wonder =
Kieran Kelleher 165.1 38
Kieran Kelleher 202.1 39 The best way to learn a new concept is to actually use it, and what better way than to do something practical like clone the Project Wonder git source code repository
Kieran Kelleher 165.1 40
Kieran Kelleher 202.1 41 * [[Downloading Wonder>>http://wiki.objectstyle.org/confluence/display/WONDER/Getting+the+Wonder+Source+Code]] Wiki Page
Kieran Kelleher 165.1 42
Kieran Kelleher 202.1 43 = Use Git with a Subversion Project =
David Avendasora 200.1 44
Kieran Kelleher 202.1 45 OK, so you want to use Git but you are working on a team project that is hosted in a subversion repository ... and it is making you depressed :-( . Well, you can still use Git to manage your local SVN working copy and be almost happy again (Either way, you won't be 100% happy unless the repository is a git one.)
David Avendasora 200.1 46
Kieran Kelleher 202.1 47 There are a couple ways of doing this. Two of them are:
David Avendasora 200.1 48
Kieran Kelleher 202.1 49 * Follow these [[Instructions>>http://www.lostechies.com/blogs/derickbailey/archive/2010/02/03/branch-per-feature-how-i-manage-subversion-with-git-branches.aspx]] to manually set up the integration.
50 * Use [[SourceTree>>http://itunes.apple.com/us/app/sourcetree-git-hg/id411678673?mt=12]] which can clone your SVN repository locally as a full Git repository including all historical SVN commits and their metadata.
David Avendasora 200.1 51
David Avendasora 198.1 52 = Git Goodies for WebObjects Developers =
Kieran Kelleher 165.1 53
David Avendasora 198.1 54 This is a list of tools that other WebObjects developers have found to be helpful. It's not a comprehensive list, and if you find things not listed here please add them
Kieran Kelleher 135.1 55
Kieran Kelleher 202.1 56 === EGit ===
57
58 EGit is a plugin for Eclipse 3.6. It's not as good as Tower or GitX, but you can use it for most tasks (add, commit, push, pull).
59
60 * [[EGit/Git For Eclipse Users>>http://wiki.eclipse.org/EGit/Git_For_Eclipse_Users]]
61 * [[User Guide>>http://wiki.eclipse.org/EGit/User_Guide]]
62 * Installation
63 *1. In Eclipse, select //Help > Install New Sofware...//
64 *1. Select the "Helios" download site from the Work with: combo box
65 *1. Expand the "Collaboration" group
66 *1. Select the EGit plugin, click Next
67 *1. Complete the install process and agree to the license, etc.
68 *1. Restart Eclipse.
69
Kieran Kelleher 155.1 70 === Git Bash Completion ===
71
72 This is really an absolute necessity and a **huge** productivity improvement. Basically you need the bash completion script from the source tarball and use your shell profile to include it whenever you open a shell. See the **Auto-Completion** section on this page:
73 [[Git Bash Auto-Completion>>http://progit.org/book/ch2-7.html]]
74
Kieran Kelleher 202.1 75 === SourceTree by Atlassian ===
Kieran Kelleher 137.1 76
Kieran Kelleher 202.1 77 SourceTree is a free Git/Mercurial GUI for OS X. A key feature is that it can use git-svn to "Clone" a SVN repository into a standard Git repository with your full SVN commit history and maintains a link back to the SVN repository. This allows you to easily use Git locally for development but still do your final commits to SVN.
Kieran Kelleher 135.1 78
Kieran Kelleher 202.1 79 * [[SourceTree on AppStore>>http://itunes.apple.com/us/app/sourcetree-git-hg/id411678673?mt=12]]
80 * [[SourceTree Home Page>>http://www.sourcetreeapp.com/]]
81
jbrook 207.1 82 === GitX (L) git GUI ===
Kieran Kelleher 202.1 83
jbrook 207.1 84 While most (if not all) Git GUI apps will never be able to emulate all the intricate functionality of Git, one advantage of a GUI app is more convenient and faster browsing/visualization of history and inter-relationships of branches. While development on the original open source GitX.app has waned, this fork of the original has continued to mature into a nice Git client, and is useful for common every day Git operations. However, power users (aka "cool kids") will probably only use it for history viewing while they continue to use the terminal command line for checkouts, branching, staging, rebasing and committing.
85 [[GitX (L) Home Page>>http://gitx.laullon.com/]]
Kieran Kelleher 202.1 86
jbrook 207.1 87 Note this app replaces the original [[GitX>>http://gitx.frim.nl/]] by Pieter de Bie.
88
Kieran Kelleher 137.1 89 === Open in GitX ===
Kieran Kelleher 135.1 90
91 [[Open In GitX Finder Droplet>>http://code.google.com/p/git-osx-installer/wiki/OpenInGitX]]
92
Kieran Kelleher 202.1 93 === Git Tower ===
Kieran Kelleher 135.1 94
Kieran Kelleher 202.1 95 [[Git Tower>>http://www.git-tower.com/]] is a commerical app for those of you who just get panic attacks at the thought of using the Terminal.
Kieran Kelleher 135.1 96
David Avendasora 198.1 97 I use Tower (bought it), but only for committing and fixing merge conflicts. I think Tower misses quite a bit of the flagship feature of GIT: branches. You can't see a branch tree graphically, like you can with gitX or even the command line (git log -graph -color, IIRC). But it's cool for committing. For everything else I use command line.
98 Miguel Arroz
Kieran Kelleher 169.1 99
jbrook 207.1 100 === Gitolite - A Git Repository Server ===
101
102 Need a way to host a few dozen or hundred repositories with dead simple administration? Look no further than the free and open-source [[gitolite>>http://sitaramc.github.com/gitolite/]]. You just need a single dedicated user account on some unix based OS. Once installed and configured, you can perform administration tasks such as adding users, adding repositories and setting fine-grained user access privileges all from your own desktop.
103
104 The best place to start is probably the ProGit chapter on gitolite, which is maintained by the author of gitolite, and is right here:
105 [[Pro Got Gitolite Chapter>>https://github.com/sitaramc/gitolite/blob/pu/doc/progit-article.mkd]]
106
107 Some tips/gotchas to keep in mind when setting up gitolite
108
109 * Make sure you give the gitolite user ownership of the admin public ssh key after copying the key over
110 * Rename your public keyname to username.pub, where username is the name you want to use to identify yourself when configuring gitolite access control to repositories.
111 * During setup, gitolite creates the file /.ssh/authorized//keys in the gitolite user account. Ensure it has permissions of 600. If not change it//
112 * If other system users such as apache, chiliproject or redmine need [[read access to the gitolite repositories to allow integration>>http://www.giocc.com/public-repositories-in-gitolite-with-umasks.html]], then you probably want to change the $REPO//MASK configuration value from 0077 to 0027 in the [[gitolite configuration file>>http://sitaramc.github.com/gitolite/rc.html]]//
113
Kieran Kelleher 202.1 114 = Unique Git Concepts =
115
David Avendasora 200.1 116 === Rebasing ===
David Avendasora 198.1 117
118 Rebasing is unique to git. There is no counterpart in Subversion.
119
120 Rebasing cuts down on the spaghetti history of merging and helps to keep history nice and linear.
121
122 Conceptually, when I rebase my current branch A on another branch B, git removes all my branch A commits back to the common ancestor of A and B, stashes those commits away temporarily, moves the head of the current branch A to the tip of the other branch B, and then re-applys all my stashed commits as **new commit** patches to my branch B.
123
124 However before using it on work that is shared with others you MUST follow the these rules, otherwise you will screw everyone else on the project.
125
Kieran Kelleher 202.1 126 * If you don't understand rebasing, don't use it You can learn more about it here:
127 ** [[http://progit.org/book/ch3-6.html]]
128 ** [[http://www.eecs.harvard.edu/~~cduan/technical/git/git-5.shtml]]
129 ** [[http://book.git-scm.com/4_rebasing.html]]
130 ** [[http://blip.tv/file/4094727]]
131 * Use rebase only on **private** branches
132 * Use rebase only for commits that have **not been pushed** to a remote repo
David Avendasora 200.1 133
Kieran Kelleher 202.1 134 === Push/Pull vs Commit/Update ===
135
136 It may be helpful to separate "push/pull" in your mind from "commit/update". Say that I have a bunch of changes that I want to --commit to Wonder-- share with the community. I am not going to push my changes. I am going to check in my changes to my repository (either a clone or a fork) and then push from my repository or generate a pull request from my repository. My repository should be fully checked in before I do this.
137
138 Say that I do not want to check in all of the changes I am looking at. The answer seems to be that you create a branch, take the changes you want to share, commit them and then share from that branch. And, again, before one generates the pull request or does the push, the branch should be clean and all changes in it should be committed.
139
140 What if one wants to generate a pull request the origin and also push to a fork? You would do this if you were not a Wonder committer but wanted to share code. You organize your changes in your local repository/branch and, from the clean repository or branch, generate the pull request and, separately, push the changes to your fork.
141
142 === Testing a Pull-Request ===
143
144 It may not be obvious how to do this. If one is a committer, there is a button one can push to automatically accept a pull-request. But is this really a safe thing to do? But how can you get the diffs being suggested? It seems more complicated than it needs to be to merge the branch the pull-request was made from. One can actually use a URL that specifies just the diff. If the pull-request is at [[https://github.com/projectwonder/wonder/pull/43]], one can do:
145
146 {{code}}
147 curl 'https://github.com/projectwonder/wonder/pull/43.patch' | git am
148 {{/code}}
149
150 The curl fetches the diff. Take off the "git am" to just see the diffs. The "git am" merges the diffs. Then you may build and test the pull-request. A normal push will push the code into the repository.
151
152 === How Easy Are Branches? ===
153
154 It may be helpful to realize this. You should become comfortable with branching. In svn, branching is hard but it is not hard in git. If you have a thought, mull over that thought for a few minutes and jot something down, you have done enough to justify a branch and the branch will be not much harder than finding the post-its on your desk, and perhaps easier. Think about when you would have created a branch in svn. For that amount of work and to establish that level of separation, in git you would create a fork, or create a new repository.
155
156 Might you end up with too many branches? Perhaps. How messy is your desk? If you are a clean-desk person, you will probably not have too many branches. You will organize and combine your branches. You will rebase your branches. You may delete your branches. After all, you had the thought. You can write the code again. If it is too distracting to keep the branch relevant, tuck the thought into the back of your head, delete the branch, let it go and move on. If you are a messy-desk person, you will probably have lots of branches. It would probably be a good thing to clean up, merge and rebase your branches before you try to share your changes. But that is obvious. Nobody wants to see how messy your desk is.
157
158 Keep in mind that the difficult part of what you do should be the thinking. Git makes it easy to organize and share your thoughts as branches. Your local copies may be messy or not. They are the thoughts you have in your head and lots of those thoughts will stay there and never see the light of day and that is ok. But when you have clarified your thoughts, git will make it easy to share them.
159
160 === Finding the List of All Git Commands ===
161
162 The "git help" command gives one the list of commonly used git commands. How does one find the others, since some of them turn out to be very useful? I tried "git help v". That was wrong. It would have been better to try "git help help", but this did tell me about the -all flag, which actually lists out all of the commands, and there are quite a few of them. So, good hunting.
163
164 = Git Everyday Tasks =
165
166 === How to revert? ===
167
168 Reverting is easy. The following command removes all modifications to files in your working copy and brings them back to the HEAD.
169
170 {{code}}
171
172 git reset --hard
173
174 {{/code}}
Ray Kiddy 211.1 175
176 === Stash to Clean and Checkout from Stash to Work ===
177
Bastian Triller 213.1 178 Say that you have several different things going on in your project at any one time. How can you seperate them to check something in? You know about the "git stash" command, which cleans up your project. But what if you want part of the dirtiness, but not all of it?
Ray Kiddy 211.1 179
180 Suppose you have file1.java, file2.java, file3.java, and file4.java. You have a single feature implemented in file1.java and file3.java and those edits stand on their own. If you are going to check in just file1.java and file3.java, you should test them on their own, without your other changes. First, do a "git stash". A "git status" will show you have no staged changes. Now do:
181
182 {{code}}
183
184 git checkout stash@{0} -- file1.java
185 git checkout stash@{0} -- file3.java
186
187 {{/code}}
188
Bastian Triller 213.1 189 Now you have your two files and not the others and you can build and test them in a clear project before you check them in
Ray Kiddy 211.1 190 One odd thing I noticed is this. The "git diff" you were doing before the stash will show your changes. Now you have to do "git diff HEAD". Not completely sure why, but there it is.