Your First Git Repositories

27 Jan

Creating a New Git Repository

Open up a terminal and cd into a directory where your project will live (or where an existing, non version-controlled project lives).

Type:

$ git init

You’ve now got a new repo.

gitignore

For new projects, you’ll probably want to create a .gitignore file to tell Git which files that you never want versioned. So open up a text editor, make a new file named .gitignore.

If you are building a Rails project you probably want to add things like:

log/*.log
tmp/**/*
doc/api
doc/app

If you are building a Java application using Eclipse and Maven, you might want something like:

.classpath
.project
.settings/
target/

There’s probably more that you’ll need to add to your project files, but that’s the idea.

For more on gitignore, see http://www.kernel.org/pub/software/scm/git/docs/gitignore.html

Cloning a Git Repository

The other (probably most common) way to get your hands on a repository, is to clone an existing one.

Something like:

$ git clone git://yourhost.com/path/to/repo-name.git

or

$ git clone https://hosthost.com/path/to/repo-name.git

or

$ git clone file:///local/path/to/repo-name.git

Adding Files and Committing Changes

Neither the act of creating a new repository nor cloning an existing repository adds any files to your changeset. You can edit files in your project, but the act of doing a commit will not commit any changes until you do a git add.

git status shows you the current status of your repo. If you haven’t modified any files, you’ll see something like:

$ git status
# On branch master
nothing to commit (working directory clean)

If you’ve modified files, but not added them to the changeset, you’ll see something like:

$ git status
# On branch master
# Changed but not updated:
#   (use "git add ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
#	modified:   CHANGED-FILE-NAME
#
no changes added to commit (use "git add" and/or "git commit -a")

Adding Files

To add all files (that aren’t excluded by .gitignore):

$ git add .

or to add a specific file


$ git add file-or-folder-name


git commit

commit the changes, and it’s always good to add a comment.

From Git Community Book:

A note on commit messages: Though not required, it’s a good idea to begin the commit message with a single short (less than 50 character) line summarizing the change, followed by a blank line and then a more thorough description. Tools that turn commits into email, for example, use the first line on the Subject: line and the rest of the commit message in the body

Common Way to Add Files As You Commit

git commit -a
Adds all changed files to stage before committing.

That’s good for today …

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • Tumblr

Installing Git

24 Jan

It’s pretty easy to get Git installed.

1.) Install Based on Your Operating System

Linux

You may already have git installed. If not, use your package manager:

$ yum install git-core

or

$ apt-get install git-core

Mac

For 10.5 or later, download and install the appropriate installer from http://code.google.com/p/git-osx-installer/

Windows

Download and install the latest installer from http://code.google.com/p/msysgit/

Note to Windows Users

There are several nice GUIs for Git on Windows. It is fine to use these, but I would highly recommend learning the basics of Git using the command line. Because:

  • You’ll better understand what’s going on which will allow you to better troubleshoot if you encounter a problem down the road when working with your GUI
  • You will more than likely find yourself in front of a Unix environment one day and you’ll already know how to deal w/ Git.

2.) Verify Git is Installed

Open up a command prompt, terminal, console or whatever you want to call it and type:

$ git

If you see something like :

$ git: command not found

Something’s not right. Try installing again and take a look at your PATH environment variable.

But if you see something like:

usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
           [-p|--paginate|--no-pager] [--no-replace-objects]
           [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
           [--help] COMMAND [ARGS]

The most commonly used git commands are:
   add        Add file contents to the index
...

You’re good to go!

3.) Configure Your User Name

After you have Git installed, a terminal and set your name and email address for Git to use to sign your commits:

$ git config --global user.name "John Doe"
$ git config --global user.email "jdoe@domain.com"

More Information

The Git Community Book has a little more detail on installing Git for your operating system here: http://book.git-scm.com/2_installing_git.html

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • Tumblr

Hello World

23 Jan

git init

I’ve been a long time Subversion (SVN) user. I have no big complaints with SVN. I used CVS and *cough* SourceSafe before switching almost exclusively to SVN. SVN has been a pleasure compared to those two version control systems!

It seems like Git is here to stay, and I know that distributed version control is the way to go. I’ve put off using in for my projects long enough and am going to post my thoughts, trials and tribulations with Git as I learn it and switch my projects from SVN to Git.

Subscribe and stay tuned …

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • Tumblr