Wiki source code of Getting Started with Git

Version 89.1 by Kieran Kelleher on 2011/08/10 22:15

Show last authors
1 {{toc}}{{/toc}}
2
3 = Got Git? No? Get Git =
4
5 * Official Download Site: [[http://git-scm.com/download]]
6 * Direct Download Links:
7 ** MacOS X [[.dmg Binary Installers>>http://code.google.com/p/git-osx-installer/]]
8 ** Microsoft Windows [[.exe Binary Installers>>http://code.google.com/p/msysgit/]]
9
10 {{info title="Git is included with XCode 4.x"}}
11
12 XCode 4.x installs a copy of git in /usr/bin/git
13
14 {{/info}}
15
16 = Learn About Git =
17
18 * Learn the concepts.
19 ** Scott Chacon (of GitHub) Video Intro [[http://www.youtube.com/watch?v=ZDR433b0HJY]]
20 ** [[This>>http://www.eecs.harvard.edu/~~cduan/technical/git/]] is an excellent tutorial on the basic concepts behind Git
21 ** [[Git for Computer Scientists>>http://eagain.net/articles/git-for-computer-scientists/]] gives another good view on the underlying concepts
22 * Learn the basics.
23 ** [[Everyday GIT With 20 Commands Or So>>http://www.kernel.org/pub/software/scm/git/docs/everyday.html]]
24 ** [[Free Online Pro Git book>>http://progit.org/book/]]
25 *** There is even a free epub version for your iPad/iPhone [[https://github.s3.amazonaws.com/media/progit.epub]]
26
27 * Get familiar with the reference materials available online
28 ** Official [[Git Documentation>>http://git-scm.com/documentation]] Site
29 ** Official [[Git User Manual>>http://www.kernel.org/pub/software/scm/git/docs/user-manual.html]]
30 ** [[Git Reference>>http://gitref.org/index.html]]
31
32 * Git Cheat Sheets
33 ** [[http://cheat.errtheblog.com/s/git/]]
34 ** [[http://ktown.kde.org/%7Ezrusin/git/git-cheat-sheet-medium.png]]
35
36 * [[Linus Torvalds talks about git>>http://www.youtube.com/watch?v=4XpnKHJAok8]]
37 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.//
38
39 = Get Started with Project Wonder =
40
41 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
42
43 * [[Downloading Wonder>>http://wiki.objectstyle.org/confluence/display/WONDER/Getting+the+Wonder+Source+Code]] Wiki Page
44
45 = Use Git with a Subversion Project =
46
47 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 happy again
48
49 I recommend you just use the [[git+svn protocol>>http://www.lostechies.com/blogs/derickbailey/archive/2010/02/03/branch-per-feature-how-i-manage-subversion-with-git-branches.aspx]].
50
51 = Git Goodies for WebObjects Developers =
52
53 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
54
55 === EGit ===
56
57 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).
58
59 * [[EGit/Git For Eclipse Users>>http://wiki.eclipse.org/EGit/Git_For_Eclipse_Users]]
60 * [[User Guide>>http://wiki.eclipse.org/EGit/User_Guide]]
61 * Installation
62 *1. In Eclipse, select //Help > Install New Sofware...//
63 *1. Select the "Helios" download site from the Work with: combo box
64 *1. Expand the "Collaboration" group
65 *1. Select the EGit plugin, click Next
66 *1. Complete the install process and agree to the license, etc.
67 *1. Restart Eclipse.
68
69 === Git Bash Completion ===
70
71 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:
72 [[Git Bash Auto-Completion>>http://progit.org/book/ch2-7.html]]
73
74 === GitX git GUI ===
75
76 GitX is an awesome FREE history viewer made for OS X. It is a better way to visualize your branch and commit history of your git repository. 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.
77 [[GitX Home Page>>http://gitx.frim.nl/]]
78
79 === Open in GitX ===
80
81 [[Open In GitX Finder Droplet>>http://code.google.com/p/git-osx-installer/wiki/OpenInGitX]]
82
83 === Git Tower ===
84
85 [[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.
86
87 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.
88 Miguel Arroz
89
90 = Unique Git Concepts =
91
92 === Rebasing ===
93
94 Rebasing is unique to git. There is no counterpart in Subversion.
95
96 Rebasing cuts down on the spaghetti history of merging and helps to keep history nice and linear.
97
98 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.
99
100 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.
101
102 * If you don't understand rebasing, don't use it You can learn more about it here:
103 ** [[http://progit.org/book/ch3-6.html]]
104 ** [[http://www.eecs.harvard.edu/~~cduan/technical/git/git-5.shtml]]
105 ** [[http://book.git-scm.com/4_rebasing.html]]
106 ** [[http://blip.tv/file/4094727]]
107 * Use rebase only on **private** branches
108 * Use rebase only for commits that have **not been pushed** to a remote repo
109
110 === Push/Pull vs Commit/Update ===
111
112 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.
113
114 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.
115
116 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.
117
118 === Testing a Pull-Request ===
119
120 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:
121
122 {{code}}
123 curl 'https://github.com/projectwonder/wonder/pull/43.patch' | git am
124 {{/code}}
125
126 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.
127
128 === How Easy Are Branches? ===
129
130 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.
131
132 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.
133
134 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.
135
136 = Git Everyday Tasks =
137
138 === How to revert? ===
139
140 Reverting is easy. The following command removes all modifications to files in your working copy and brings them back to the HEAD.
141
142 {{code}}
143
144 git reset --hard
145
146 {{/code}}