Initialise GIT Project Tutorial

In Uncategorized on 12/02/2011 by pier0w

Git is a really nice distributed source control system. A distributed source control system allows every person working with it to have a local copy of the entire source repository including all of it’s change history, so the only difference between the copy of the repository on your machine and the central repository is that everyone has decided to push their changes to the central repository.

This means you are able to make local commits without ever worrying about clashing with other developers. Clashes can only ever then occur when you finally decide to push all your changes to the central repository and since GIT has such fantastic auto merge capabilities you will very rarely have to worry about dealing with clashes your self. I find that this ease of committing makes me commit much more than I usually would with SVN since all of my commits will succeed every time.

So to get git to start monitoring your files move into your projects directory and run the git init command.

#> cd project/
#> git init
Initialized empty Git repository in /some/dir/project/.git/

You can now check to see what git has found in your project with the git status command.

#> git status
# On branch master
# Initial commit
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#	pom.xml
#	src/
nothing added to commit but untracked files present (use "git add" to track)

Since this is a maven project It has found the maven pom file and the source directory for your project. Now you can actually tell git to start tracking these by adding them to the repository and then carrying out our first commit.

#> git add pom.xml src/
#> git status # Just running git status again to check what files have been added.
# On branch master
# Initial commit
# Changes to be committed:
#   (use "git rm --cached ..." to unstage)
#	new file:   pom.xml
#	new file:   src/main/java/org/project/
#	new file:   src/test/java/org/project/
#> git commit -m "First commit." # Our first commit. Ignore the warnings, you can do what it says to stop git complaining if you like.
[master (root-commit) 4100aeb] First commit.
 Committer: Some One 
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global "Your Name"
    git config --global

If the identity used for this commit is wrong, you can fix it with:

    git commit --amend --author='Your Name '

 3 files changed, 76 insertions(+), 0 deletions(-)
 create mode 100644 pom.xml
 create mode 100644 src/main/java/org/project/
 create mode 100644 src/test/java/org/project/

Git is now tracking all the files within your project and will pick up any changes you make.


2 Responses to “Initialise GIT Project Tutorial”

  1. […] Ok so next we need get git to start tracking the changes on the project so move into the projects directory and run through the Initialise GIT Project Tutorial. […]

  2. […] So lets begin our first very simple hibernate project. So the first thing to do is create a project and then get git to track your changes. […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: