Changes for page Getting Started with Git
Last modified by Bastian Triller on 2013/05/21 17:24
From version 98.1
edited by Kieran Kelleher
on 2011/08/09 12:54
on 2011/08/09 12:54
Change comment:
There is no comment for this version
To version 99.1
edited by Kieran Kelleher
on 2011/03/21 18:44
on 2011/03/21 18:44
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Title
-
... ... @@ -1,1 +1,1 @@ 1 - GettingStarted with Git1 +git - Content
-
... ... @@ -1,75 +1,15 @@ 1 - {{toc}}{{/toc}}1 += Learning About git = 2 2 3 -= Got Git? No? Get Git = 3 +[[Free Online Pro Git book>>http://progit.org/book/]] 4 +[[Git User Manual>>http://www.kernel.org/pub/software/scm/git/docs/user-manual.html]] 5 +[[Git Reference>>http://gitref.org/index.html]] 4 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/]] 7 += Install Git = 9 9 10 - {{infotitle="Gitisincluded withXCode4.x"}}9 +[[OS X dmg Installer>>http://code.google.com/p/git-osx-installer/]] 11 11 12 - XCode4.xinstallsa copyof git in /usr/bin/git11 += Git Goodies = 13 13 14 -{{/info}} 15 - 16 -= Learn About Git = 17 - 18 -* Learn the concepts. 19 -** [[This>>http://www.eecs.harvard.edu/~~cduan/technical/git/]] is an excellent tutorial on the basic concepts behind Git 20 -** [[Git for Computer Scientists>>http://eagain.net/articles/git-for-computer-scientists/]] gives another good view on the underlying concepts 21 -* Learn the basics. 22 -** [[Everyday GIT With 20 Commands Or So>>http://www.kernel.org/pub/software/scm/git/docs/everyday.html]] 23 -** [[Free Online Pro Git book>>http://progit.org/book/]] 24 -*** There is even a free epub version for your iPad/iPhone! [[https://github.s3.amazonaws.com/media/progit.epub]] 25 - 26 -* Get familiar with the reference materials available online 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 -** [[http://ktown.kde.org/%7Ezrusin/git/git-cheat-sheet-medium.png]] 34 - 35 -* [[Linus Torvalds talks about git>>http://www.youtube.com/watch?v=4XpnKHJAok8]] 36 -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.// 37 - 38 -= Get Started with Project Wonder = 39 - 40 -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 41 - 42 -* [[Downloading Wonder>>http://wiki.objectstyle.org/confluence/display/WONDER/Getting+the+Wonder+Source+Code]] Wiki Page 43 - 44 -= Use Git with a Subversion Project = 45 - 46 -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 47 - 48 -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]]. 49 - 50 -= Git Goodies for WebObjects Developers = 51 - 52 -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 53 - 54 -=== EGit === 55 - 56 -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). 57 - 58 -* [[EGit/Git For Eclipse Users>>http://wiki.eclipse.org/EGit/Git_For_Eclipse_Users]] 59 -* [[User Guide>>http://wiki.eclipse.org/EGit/User_Guide]] 60 -* Installation 61 -*1. In Eclipse, select //Help > Install New Sofware...// 62 -*1. Select the "Helios" download site from the Work with: combo box 63 -*1. Expand the "Collaboration" group 64 -*1. Select the EGit plugin, click Next 65 -*1. Complete the install process and agree to the license, etc. 66 -*1. Restart Eclipse. 67 - 68 -=== Git Bash Completion === 69 - 70 -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: 71 -[[Git Bash Auto-Completion>>http://progit.org/book/ch2-7.html]] 72 - 73 73 === GitX git GUI === 74 74 75 75 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. ... ... @@ -79,75 +79,77 @@ 79 79 80 80 [[Open In GitX Finder Droplet>>http://code.google.com/p/git-osx-installer/wiki/OpenInGitX]] 81 81 82 -== =Git Tower ===22 +== Git Tower == 83 83 84 -[[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. 24 +For those of you who just get panic attacks at the thought of using the Terminal, there is a commercial app for that: 25 +[[Git Tower>>http://www.git-tower.com/]] 85 85 86 -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. 87 - Miguel Arroz 27 += Using git locally on a Subversion Working Copy = 88 88 89 - =UniqueGitConcepts=29 +OK, so you are addicted to git, and now you have to work on a team project that is hosted in a remote subversion repository ... and it is making you depressed :-(. Well, you can use manage your local svn working copy using git and be happy again! 90 90 91 - ===Rebasing===31 +There is a git-svn tool (type man git-svn in the terminal for details), but that adds yet another tool into the mix that you have to learn. So while you could use it and YMMV for projects tht are going to be on svn forever, 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]] instead, especially if you are typically working on one particular branch of the remote svn repository. 92 92 93 - Rebasingisuniqueto git.Thereisnocounterpart inSubversion.33 += I want to learn git before I switch from Subversion = 94 94 95 -Rebasing cuts down on the spaghetti history of merging and helps to keep history nice and linear. 35 +(This kind of repeats some of the previous section, but that's on purpose so we can condition you brain to start using git right now ;-) ) 36 +Even while you are working with svn repositories, you can start learning and taking advantage of git right now by making your local svn working copy an actual local git repository. The idea is to use the appropriate ignore feature of each SCM system to ignore the hidden files of the other system. The concept is described here: 96 96 97 - Conceptually, when I rebase my currentbranch Aon anotherbranch B,gitremoves all my branch A commits back tothecommon ancestor of A and B,stashes thosemitsaway temporarily, moves the head of the current branchA to the tip of theotherbranchB, and thenre-applys all my stashed commitsas **new commit** patchesto mybranchB.38 +[[**git+svn** Working Protocol>>http://www.lostechies.com/blogs/derickbailey/archive/2010/02/03/branch-per-feature-how-i-manage-subversion-with-git-branches.aspx]] 98 98 99 - Howeverbefore using itonworkthat isshared with others youMUSTfollowthethese rules, otherwiseyouwillscreweveryoneelseonthe project.40 +When you first learn about git and you google "git svn" you will learn about a command line tool git-svn which works directly with remote svn repos. Unless you want to use git locally to switch between svn branches, I don't recommend it. Use the **git+svn** approach outlined in above blog post instead. 100 100 101 -* If you don't understand rebasing, don't use it You can learn more about it here: 102 -** [[http://progit.org/book/ch3-6.html]] 103 -** [[http://www.eecs.harvard.edu/~~cduan/technical/git/git-5.shtml]] 104 -** [[http://book.git-scm.com/4_rebasing.html]] 105 -** [[http://blip.tv/file/4094727]] 106 -* Use rebase only on **private** branches 107 -* Use rebase only for commits that have **not been pushed** to a remote repo 42 +Once you start using git, it becomes addictive ....... you can never go back ...... really, it's that good ...... and it is not hard. 108 108 109 - ===Push/PullvsCommit/Update===44 +Some tips for Eclipse setup and general workflow when using git locally on svn working copies, 110 110 111 -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. 46 +* check out the entire svn branch that you work on using the command line, then LINK (import no copy) the projects you want in your workspace using the Subclipse import tool, and 47 +* Do your git operations (status, staging, commit, diff, branching, checkouts, rebase and merge using the terminal). git on the terminal is efficient... honest. 48 +* Do all your local work and cimmits on branches other than the master branch. 49 +* Switch to master branch to update from svn and commit those svn updates on the master branch. 50 +* Merge your working branch(es) with or rebase your working branch(es) from the master and just keep on working. 51 +* Switch to master branch before synchronizing with remote svn repo. 52 +* You can use ##git stash## to temporarily put aside your uncommitted changes before doing an svn update. Then use ##git stash pop## to replay those uncommitted changes onto the working copy. 112 112 113 - SaythatI donot wanttocheck inallofthe changesI am lookingat. Theanswer seems tobethat you create a branch,take the changes you wantto share,committhemd then share from that branch. And, again, before one generates the pull request ordoesthe push, the branchshould be cleanand all changesin it should becommitted.54 +{{code title="Anatomony of an svn update operation on a git-managed svn working copy"}} 114 114 115 -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. 116 116 117 -=== Versions? or Diffs? === 57 +# Assume you are currently on a working branch. Verify this and check for uncommitted changes. 58 +git status 118 118 119 -One satori that I had is this. Subversion is all about versions. CVS was all about versions. We have been working with these a long time and the ideas are sticky. Git is //not// about versions. It is about diffs. Diffs are the main thing. If you think about it, this makes sense. You have thoughts and make changes and those diffs are the product of your work. If you get those diffs into something, that is good, but the work product was the diffs. 60 +# Either commit your local changes to your working branch 61 +# using 'git add' + 'git commit', or temporarily stash 62 +# them using 'git stash' 63 +git stash 120 120 121 -All this rebasing and such may seem odd. But the main thing is the diffs. I have edits from a two-week old repository. What do I do? I move the diffs so that they are diffs from the latest code. That is a rebase. When we make edits, we are used to being over-concerned about merge conflicts. But they do not happen all that often and are actually easy to deal with when they do, if the tools are oriented to making them easy to deal with. If we are worrying about the versions and not the diffs, we are paying attention to the paper we write on and not to the words we are putting down. 65 +# Switch to master branch 66 +git checkout master 122 122 123 -Internally, git keeps track of text fragments and not files. Why is this? Because the versions are not the point. The diffs are. I can imagine how Linus Torvalds had this idea. He was looking at all the versions of all the files in Linux and all the e-mails of all the diffs. These are two separate worlds. It is conceptually painful to look at every diff, find its source and see how it maps to what now exists. At some point, he must have realized that all he needed was the e-mails. If he had no files any longer, but all the e-mails, he could always reconstruct the files. He would not have to make the conceptual switch from the diffs to the versions and back. Collectively, those e-mails with the diffs defined everything that needed to be said. Quod erat demonstrandum. 68 +# Ensure there are no changes either from an svn perspective 69 +# or a git perspective on the master branch. 70 +git status 71 +svn status 124 124 125 -=== Testing a Pull-Request === 73 +# Update the master branch from remote svn repo 74 +svn update 126 126 127 -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: 76 +# Commit those updates to git repo 77 +git commit -a -m "updated from remote svn repo" 128 128 129 -{{code}} 130 -curl 'https://github.com/projectwonder/wonder/pull/43.patch' | git am 131 -{{/code}} 79 +# Switch to your working branch 80 +git checkout workingbranch 132 132 133 -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. 82 +# Merge or rebase your working branch off of the updated master. 83 +# This rewinds your branch commits back to the common commit ancestor 84 +# shared between your working branch and the master branch. Then it 85 +# applies the master branch commits (the svn updates) so that this 86 +# working branch becomes identical to the master. After that it 'replays' 87 +# your working branch commits on top of the updated branch. 88 +# This ensures a clean linear progression. Rebasing is a very cool feature of git. 89 +rebase master 134 134 135 -=== How Easy Are Branches? === 91 +# Now if you stashed uncommitted changes earlier, you can pop them back into 92 +# the working copy 93 +git stash pop 136 136 137 -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. 138 - 139 -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. 140 - 141 -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. 142 - 143 -= Git Everyday Tasks = 144 - 145 -=== How to revert? === 146 - 147 -Reverting is easy. The following command removes all modifications to files in your working copy and brings them back to the HEAD. 148 - 149 -{{code}} 150 - 151 -git reset --hard 152 - 153 153 {{/code}}