Skip to content

Git Gotchas and Tips

Andrew Wooldridge edited this page Feb 6, 2014 · 20 revisions

Developing for YUI will lead you to deal with git quite often. The purpose of this page is to list several git gotchas as well as offer tips for using git with YUI. If you run into any "gotchas" please feel free to add to the list!

Also check out GitHub's own guides.

Gotchas

Branching

Without an explicit , git branch and git checkout -b default to HEAD - which is the branch you are currently on (not necessarily master). So for :

$ git checkout topic-branch-one

$ git checkout -b topic-branch-two

--> topic-branch-two would be created off of topic-branch-one, not master.

To specify which branch you would include another argument like:

$ git checkout topic-branch-one

$ git checkout -b topic-branch-three master

--> topic-branch-three branched from master instead of topic-branch-one

(see also Learn Git Branching )

Pushing

(Only committers and reviewers can push code to YUI - see YUI Contributor Model)

Never use "the big green button".

When pushing manually, you absolutely have to make sure you know the exact set of commits which will be getting pushed. Otherwise you're not avoiding any issues.

Diff your local branch with the remote branch you're about to push to. It's the cmd line equivalent of looking at the set of commits in the pull request UI.

Never push to master or 3.x. You have to push to dev-master or dev-3.x.

Git Tips

##Fundamentals

  • A branch is a parallel set of commits from an existing commit.

  • git branch foo <commit> starts this branch, foo, from

  • Everything else is just different ways to specify (as with most things in git).

    git branch foo starts foo from whichever commit you're on currently (aka HEAD - normally the tip of your checked out branch).

    git branch foo upstream/bar starts foo from the commit referenced by upstream/bar, which is the tip of the bar branch, on the remote called 'upstream'.

    git branch foo bar starts foo from the commit referenced by bar, which is the tip of your local bar branch (which may or may not be different from the upstream/bar commit. In fact your bar may have nothing to do with upstream/bar)

  • And sugar on top of git branch + git checkout

    git checkout -b foo is the same as git branch foo; git checkout foo;

    git checkout -b foo upstream/bar is the same as git branch foo upstream/bar; git checkout foo;

Shell Helpers

  • YUI Engineer Derek Gathright created a simple shell script to help YUI developers stay up-to-date with all the various branches in YUI. yui-sync.sh

  • You should include in your .bash_profile (or equiv) a script like this one that displays the current git branch whenever you are inside a repo.

Cheat Sheets and Documentation

  • There are many versions of of cheat sheets on the web, here is one exampleGit Cheat Sheet
  • Getting a grasp on the fundamentals of git is essential to understanding why you may run into issues with branches or pull requests. This online documentation is one of the best available to learn more about git.

2

Clone this wiki locally