At a page such as http://git-dev.drupal.org/node/3060/git-instructions contains instructions for cloning the project, and lists it as a "one-time" operation. That's basically true, as long as you know how to switch to another version if you need to. That part isn't currently documented on the page and I spent about an hour on IRC tonight trying to work through it with amorfati and lut4rp (totally due to my n00bishness).

I think we could do with another heading under the "Routinely" section that is something like:

<h2>Switch to a different version</h2>
<code>
git branch -r # view list of available branches
git checkout [branch-name] # e.g. git checkout 6.x-1.x

git tag # view list of available tags
git checkout [tag-name] # e.g. git checkout 6.x-1.0
<code>

That's actually all there is to it. Git seems to automatically create a tracking branch for you somehow based on the naming convention (NO idea how it does that magic).

But I got terribly confused about local vs. remote branches, since remote branches don't show up with "git branch" like local tags do, and I didn't know where to find my branches. Then once I found them, they were named like "origin/6.x-1.x" and I didn't understand that you didn't need to checkout to "origin/6.x-1.x". And finally, you don't do "git checkout -b [branch-name]" (which is the other command that's documented here) because that creates a branch with the same name as a legit branch but which is NOT a tracking branch, leading to all kinds of pain and horror.

So... yes. Can we please add a section like this to the page? :D

Comments

webchick’s picture

Also, everything I just said up above should definitely be verified by someone who actually knows Git. ;P

mark trapp’s picture

Status: Needs review » Active

I think this is a good idea (I'm amorfati on IRC). A couple of quick points:

1. I already mentioned in IRC, but for posterity: it should be git branch -a instead of git branch -r. git branch -r only shows remote branches, not all available.

2. git creates remote tracking branches based on what it cloned from the remote repository. So the local branch names are always the same as the remote branch names after a clone, which is why git can automagically create the tracking. Otherwise, you need to create it manually and specify the names of both the local and remote branches to track. But for most people (and for the purposes of the cheat sheet), git clone should be assumed as the first step, so there won't be a need to manually create tracking branches at all.

3. I think the big thing to remove is the -b argument from git checkout. That's just incorrect, especially after the use of git clone.

4. I'd also question the use of git rebase in creating patches, as that's some pretty heavy git wizardry that's generally only needed for edge cases. I presume someone thought that out and there's a good reason, but it's a thing that even git masters argue about how to use correctly, and not something you'd generally put in a cheat sheet targeted towards total newcomers and people who don't want to think about how to create a patch (like me). withdrawn for now

(removed a bunch of requests for info that's already there for maintainers)

webchick’s picture

Status: Active » Needs review

New directions are up @ http://git-dev.drupal.org/node/3236/git-instructions for example. They look great to me! Marking to "needs review" so some more Gitty-style people can take a look.

webchick’s picture

And Mark, could you maybe create a separate issue to talk about the patch instructions? I'd love to keep this one focused to just the branch/tag switcharoo, and that patch thing is likely a much longer discussion.

Thanks for your help earlier! Much appreciated. :D

mark trapp’s picture

After discussing it in IRC, I withdraw point 4 until a later date, so it's all good.

A point about tags; checking out a tag isn't something you can contribute on: you need to check out a branch (same as CVS). I wonder if it's necessary to even mention checking out tags in the cheat sheet. We don't mention it in the CVS instructions.

dww’s picture

Status: Active » Needs review

Checking out from tags is a great idea when deploying code for a real website, not for doing development. So, I think that warrants a few lines on the Git instructions tab, since that's targeting a lot of possible audiences: maintainers, developers, contributors, users, etc. So, +1 to leaving that in there.

Where's the issue about the patch instructions? I, too, think we're trying too hard to optimize for maintainers here, and throwing possible contributors into this multi-step rebase process is going to be really scary. I'd keep going, but I know I'm off topic for this thread. ;) Therefore, a link to the right place to discuss it would be much appreciated...

Cheers,
-Derek

lut4rp’s picture

Hmm, I suggest we change `git branch -a` to `git branch -r`. That gives us just the remote branches that CAN be set up with corresponding local branches. After that, we split the commands into 2 sections like, "To see all remote branches, do a git branch -r" and then, "To set up a local branch to correspond to a remote branch, do a git checkout BRANCHNAME".

Thoughts?

mark trapp’s picture

We were discussing this in IRC, and we're going to have a problem either way with the instructions as it stands now.

If you do git branch -a, you get a listing like:

7.x
6.x
remotes/origin/5.x
remotes/origin/4.0.x
....

If you do git branch -r, you get a listing like:

origin/7.x
origin/6.x
origin/5.x
origin/4.0.x

In either case, valid branch names for git checkout are everything after origin/. So the instructions tell you to do something bad if a remote tracking branch hasn't already been created, namely git checkout remotes/origin/7.x or git checkout origin/7.x depending on which command you run. Doing so will create a detached HEAD.

At least with git branch -a, the user has a chance of checking out the correct branch should the user already have checked it out correctly, since the local branches are at top.

We should figure out a way to clarify what the branch names are before settling on which version of git branch we should use.

mark trapp’s picture

Status: Needs review » Needs work

Set back status.

eliza411’s picture

Two things: I posted the following which I hope will be helpful as we work on docs:
http://groups.drupal.org/node/129069
It's a place for larger questions of focus and audience.

In the context of that post, I'm planning to resolve this by removing tags from Git instructions and asking someone to update http://drupal.org/node/1066342 with a better explanation of when branching a tag is appropriate.

eliza411’s picture

Also, I'm inclined to git branch -a

webchick’s picture

git branch -a and removing tags sounds good to me.

eliza411’s picture

Status: Needs work » Fixed

done.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.