Featured Post

Happy New Year!

It is just a bit early but if I wait till later I am sure to not get this posted. Happy New Year! Technorati Tags: Happy New Year

Read More

Follow @dougrdotnet on Twitter

Git – Every Day Commands

Posted by dougr | Posted in Git | Posted on 06-01-2010

Tags: , , ,

0

I’ve been using Git, rather than SVN, for the past 6 months now.  There are many powerful and useful commands, yet there are only few that I actually use on a daily basis.  So, if you are newish to Git and want a quick guide, then here you go.

Seldom Used

Create A Repository:

$ mkdir myProject
$ cd myProject
$ git init

Adding Files To The Repository

You can, if you wish, use this command following the $ git init shown in the previous example.

$ cd myProject
$ git add .

Note the [ .] following [$ git add], that is a space and a dot which means add everything below ./ in the current directory.

Often Used

Performing a Commit

This command will commit all changed files, since last commit, and remove any deleted files.

$ cd myProject
$ git commit -a

This command will commit all changed files, since last commit, and remove any deleted files. The addition of -m will allow the addition of a commit message.

$ cd myProject
$ git commit -a -m "re #xxx I just referenced a ticket number and am providing change detail."

Undoing Changes

This command will undo all changes to a file which have occurred since the last commit.

$ cd myProject
$ git checkout HEAD^ path/to/myFile


Working Remote

Getting A Remote Git Repository

This command will clone a remote repository to a local directory location.

$ git clone git@remote.url.com /local/path/directory

Updating A Local Repository With All Remote Changes

$ git pull

Updating A Remote Repository With All Local Changes

$ git push

Those are the most common commands that I use for every project. There are allot more for special situations. The Git Docs are pretty good, a bit hard to read (in my opinion), but I became accustom to it pretty quickly. My transition from SVN was relatively painless, I was up and running on an existing remote project within a few hours.

HTH!

#100blogs challenge Day4 http://bit.ly/4MtAfx