git

Starting on an existing project

When you start on a client project, you usually take the following steps.

 $ git clone  https://remotebox.example.com/project.git

List the branches:

 $ cd project
 $ git branch -a
 * master
   remotes/origin/HEAD -> origin/master
   remotes/origin/development
   remotes/origin/master
   remotes/origin/release

I'm assuming here that the client has a development branch, where you can start fixing issues. So you'll probably want to switch to the development branch:

 $ git checkout -t origin/development

My way of merging

When you want to merge a feature branch into the current development branch, perhaps you want to check out the current development branch:

  $ git clone https://remotebox.example.com/project.git
  $ cd project 

Doublecheck and see what branch you're in:

  $ git branch
  * development

Now see which branch you want to merge:

  $ git branch -a
  * development
    remotes/origin/development
    remotes/origin/development-flightsvc
    remotes/origin/master
    remotes/origin/release

Now merge that branch into your main branch but don't commit -- so you can review the changes:

  $ git merge --no-commit --no-ff origin/development-flightsvc

If all is fine:

  $ git commit -m "Merge of feature branch into main development branch"

To clean up, delete the feature branch:

  $ git branch -d development-flightsvn
  $ git push origin --delete development-flightsvn

From SVN to git

Here's a quick overview if you're moving from Subversion to git. The information below is deliberately incomplete and sometimes wrong from the git user's point of view. It's not that simple since git is of course distributed, plus branching works different, etc. But it ought to get you started, and let you find out the details later.

svn checkout <URL>git clone <URL>
svn checkout -rREVISION <URL>git clone <URL>; git reset --hard <hash>
svn revert <filename> (to throw modifications away)git checkout <filename>
svn revert <filename> (to undo an svn add)git reset <filename>
svn add <filename>git add <filename>
svn update git pull
svn commit git commit -a && git push
svn copy git branch <branchname> ; git checkout <branchname>
...then after some work is done git commit ; git push origin <branchname>
svn info git remote show origin
svn move git mv
svn diff <filename>git diff <filename> (before adding to a commit)
svn diff <filename>git diff --cached <filename> (after adding to a commit)
svn log git log (to view your commits)
svn log git log origin (to view your pushes)

Branching

Some basics:

See remote branches git branch -a
Get a new remote branch git checkout -b [branchname] origin/[branchname] && git remote update

Creating a branch afterwards

Sometimes, I enthusiastically started hacking away, only to realise I really needed to branch first. The stashes feature makes that really easy:

 $ git stash

Now you have a clean directory again without changes. All changes are saved in the stash.

 $ git checkout -b newbranch       # Create and move to a new branch
 $ git stash apply

VoilĂ , use git status to see that your changes are all here in the new branch.

Some other tidbits

To roll back (undo) an "add" action:

 $ git reset FILENAME

Ignoring files

In SVN, that's done with properties on the directory, i.e.

 $ svn propedit svn:ignore .

In Git, it's just like good ole' CVS: a file, in this case .gitignore

Links

http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging