YUILibrary - Open source JavaScript and CSS for building richly interactive software.
Fork YUI on GitHub

Git FAQ & Resources

Git Install

Mac

Leopard

  • Download and Install Git Client for OSX
  • After installation open a terminal and type: git --version
  • You should see something like this Version may vary: git version 1.5.4.5
  • Git is now installed and working

Tiger

  • Download and Install Git package for OS X
  • You will need to add /usr/local/bin to your $PATH
    • vim ~/.bashrc
    • At the bottom of the file add this line:
    • export PATH=$PATH:/usr/local/bin
  • After installation open a terminal and type: git --version
  • You should see something like this: git version 1.5.3.1
  • Git is now installed and working

Mac Ports

If you have Mac Ports installed, do the following:

  • Install the git-core package
  • sudo port install git-core
  • After installation open a terminal and type: git --version
  • You should see something like this: git version 1.6.0
  • Git is now installed and working

Fink

Git is in the unstable tree in Fink, and I couldn't get it to install. You should pick another method

Linux

Redhat

For Fedora 7 and later.

  • Install the git-core package
  • sudo yum install git-core
  • After installation open a terminal and type: git --version
  • You should see something like this: git version 1.5.2.2
  • Git is now installed and working

For Fedora 6 and older, git-core is part of Fedora Extras (http://fedoraproject.org/wiki/Extras).

For users of Red Hat Enterprise Linux and its clones (such as CentOS and Scientific Linux), users will have to build git by hand. Source available here: http://git.or.cz/

Ubuntu

  • Install the git-core package
  • sudo apt-get install git-core
  • After installation open a terminal and type: git --version
  • You should see something like this: git version 1.5.4.3
  • Git is now installed and working

Windows

  • Download and Install Git Client for Windows
  • During installation, you'll be asked which SSH Executable you'd like to use. Unless you already use plink/putty/pageant and are familiar with managing keys on it, choose "Use OpenSSH". It simplifies ssh key generation and use.
  • After installation open Git Bash and type: git --version
  • You should see something like this: git version 1.5.6.1
  • Git is now installed and working
  • Important Config Option
    You need to add this config option to help Windows deal with line endings:
    git config --global core.autocrlf true

Configuring Git

Setting these configs are the minimum that needs to be set. This way your name and email will show up in the commit messages/logs.

  • git config --global user.name "Dav Glass"
  • git config --global user.email dav.glass@yahoo.com
  • More info on other git config options
  • These configs should be written to this file (same for Windows, when working in Git Bash): ~/.gitconfig
  • Here is my current ~/.gitconfig
[merge]
   tool = opendiff
[core]
   excludesfile = /Users/davglass/.gitignore

[alias]
   st = status
   ci = commit
   co = checkout
   br = branch
[color]
   ui = auto
   status = auto
   branch = auto
    diff = never

[user]
   name = Dav Glass
   email = dav.glass@yahoo.com

And my ~/.gitignore file

.DS_Store
._*
.svn
.hg
.*.swp

Repository Information

Getting the Source

To begin development you will need to clone the yuidoc project

Note: http:// is also supported on the GitHub server.

The command for accessing a git project on our server is:

git clone git://github.com/yui/projectname.git

When issuing this command, you need to be in your working directory. It will create a directory in ./ called projectname

Here is the command needed to get the YUIDoc source code:

git clone git://github.com/yui/yuidoc.git

Making changes and committing

Git is a little different than CVS, every person has a copy of the repository on their local machine. So you can commit to it as much as you like. No build will be triggered.

Most of the built in aliases for git will help because they are similar to CVS.

  • git pull This will pull a fresh copy of the repository.
  • git commit This will commit changes to your local repository (not the server).
  • git add This is a little different, you use git add to add a file to the commit index. It's not just for new files.
  • git push This is what moves your local repository to the server you checked out from.
  • git status Shows you the status of your repository.
  • git diff Gives you a diff of the file.
  • git rm This lets you remove files and directories.

Example git add

This example shows using git add to add each file to the commit index before committing.

cd /my/working/directory
git clone git://github.com/yui/yuidoc.git
cd yuidoc
vim README
--Edit the file
git add README
git commit -m "Updated the README file"

---Then you will see something like this:
Created commit 794a86f: Updated the README file
 1 files changed, 1 insertions(+), 0 deletions(-)

Example git commit all

This example shows using git -a to commit all changed files

cd util/dd/src/js
vim drag.js
--Edit the file
git commit -a

--At this point git will open your default editor and ask for a commit message

---Then you will see something like this:
Created commit ed16907: fixed #2345: patched file to fix something
 1 files changed, 2 insertions(+), 0 deletions(-)

Resolving a Failed Push

If you encounter a (non-fast forward) error on push:

To git@github.com:username/yui3.git
! [rejected]    master -> master (non-fast foward)
error: failed to push some refs to 'git@github.com:username/yui3.git'

Generally that means that your tree is now out of sync with the main repository. You need to cd projectroot and do a git pull. This should bring your tree into sync with the repository and then it will allow you to git push.

Reverting Changes In Your Work Tree

To revert modified files in your working tree (the equivalant of cvs co -C ):

git checkout -- path/to/file

A git status will give you a list of files in your working tree which are modified.

Creating Remote Branches

NOTE: This method does not require you to switch to the local branch in order to push it to the remove server.

Create the local branch (from the branch you're currently in (generally "master")):

git branch [branch name]

Push it to the origin server:

git push origin [branch name]

Users will then be able to checkout the remote branch by using:

git checkout -b [local branch name] origin/[branch name]

Which will create a new local branch, which tracks against the remote branch, and also change the working tree to the local branch (so any changes you make, you're making to the branch).

Users can then switch between branches as required using:

git checkout [branch name]

# Switching back to "master", which is a tracking branch itself, works the same way...
git checkout "master"

Resetting to a Tag

Based on the yui3 project and pulling the tag 3.0.0beta1m1

From your cloned repo:

//Get up to date
git pull origin master

//Reset head to the tag
git checkout 3.0.0beta1m1

//Should print something like this:
Note: moving to "3.0.0beta1m1" which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
  git checkout -b <new_branch_name>
  HEAD is now at 2ba54bd... needed lenghty check for nodelist
//Now create a local branch for easy task switching:
git checkout -b beta1m1

//You can check this by calling:
git log -n1

//That commit should be the one listed above:
commit 2ba54bd1bd1ac2b4e64e4bb9510dbdbb5450cefc
Author: Adam Moore <adamoore@yahoo-inc.com>
Date:   Fri Apr 10 12:59:35 2009 -0700

    needed lenghty check for nodelist


//Now you can switch between master and this tag like this:
git checkout master //Back to the master branch

git checkout beta1m1 //Back to this tag

Using rebase and merge to keep your development branch in sync

Use rebase to apply commits downstream onto your development branch. Use merge to apply commits from your dev branch back upstream: http://sites.google.com/a/insoshi.com/insoshi-guides/Git-Guides/merge-vs-rebase

$ git checkout mybranch // checkout my dev branch
$ vi workingfiles.js // make some changes
$ git commit -a -m "edits" // commit my changes
$ git checkout master // checkout my upstream branch
$ git pull // pull from origin
$ git rebase master mybranch // apply commits from origin to dev branch
// at this point i'm in mybranch so i can keep working...

//... or i can push my commits to origin/master
$ git checkout master // back to the upstream branch
$ git merge mybranch // integrate my changes
$ git push // push my changes

Resources