Git Lifecycle: Creating a New Project (Repository)

"Project" isn't a term in Git; "repository" is what we might call a project. Creating a new one named web-client is a Git administrator duty. See Git Administration. Here are the step thereafter:

  1. Go to your gitolite-admin project.
  2. Go to the conf subdirectory.
  3. Edit gitolite.conf and add web-client. Work out the privileges, etc.
  4. Perform the following commands:
    $ git add gitolite.conf $ git commit gitolite.conf $ git push

The new project (repository) is ready to be cloned. Remember, cloning will create a subdirectory in the current working directory with the same name as the new repository.

$ git clone [email protected]:web-client Initialized empty Git repository in /home/jack/acme/web-client/.git/ warning: You appear to have cloned an empty repository.

The new repository is empty. To populate it with existing code on the client, copy the resources (subdirectories, files, etc.) to the newly cloned repository. Then add and commit all the resources. (If this is an Eclipse project, don't blindly commit everything. Please see Git-Eclipse Peculiarities.)

Populating the new repository

The new repository is empty. To populate it with existing code on the client, copy the resources (subdirectories, files, etc.) to the newly cloned repository. Then add and commit all the resources. (If this is an Eclipse project, don't blindly commit everything. Please see Git-Eclipse peculiarities.

Committing the new contents

Here are the steps.

$ git add . $ git status (see note 1 below) $ git commit . $ git push --force origin master (see note 2 below) Counting objects: 444, done. Delta compression using up to 4 threads. Compressing objects: 100% (430/430), done. Writing objects: 100% (444/444), 936.17 KiB, done. Total 444 (delta 110), reused 0 (delta 0) To [email protected]:web-client * [new branch] master -> master

1 You don't want to commit, for example, the build or bin subdirectories of an Eclipse project if you happen already to have turned the contents of this repository into such a project. Use ''git status'' to see exactly what's going to be committed.

2 This pushes the contents all the way back to the backing server's master. It does not, for example, create the master branch if you're using the strategy outlined in Git Scheme.

Creating a personal repository and pushing it to origin

It is not necessary to create branch master; it exists as soon as the project is created. You must create any personal branch(es) you wish to work in as you work on the project.

We use a combination command to create the new master branch then check it out (switch to it) simultaneously.

$ git checkout -b jack $ git branch * jack master $ git push Everything up-to-date $ git push @git@acme:rest-server jack Total 0 (delta 0), reused 0 (delta 0) To git@acme:rest-server * [new branch] jack -> jack

Git commit log of new rest-server project

For the second incantation of rest-server, the project/repository was re-created according to the instructions above. The Eclipse project was created, re-populated with the existing source (minus some stuff that was lost), and worked on until it ran. The following is a log of what happened when I re-committed the project. Not all the commands issued are crucial; a few are merely informative along the way. I like to use git status a log to reassure myself as I go.

Also in this log are: creating branch jack, pushing it back to origin and verifying that all is working.

What is important to note here is how the Eclipse project-specific files and subdirectories are treated. How these work is discussed in Git-Eclipse peculiarities.

russ@russ-elite-book:~/acme/rest-server> git status # On branch master # # Initial commit # # Untracked files: # (use "git add ..." to include in what will be committed) # # .classpath # .gitignore # .settings/ # WebContent/ # lib/ # src/ # test/ nothing added to commit but untracked files present (use "git add" to track) russ@russ-elite-book:~/acme/rest-server> cp .project .project.sample russ@russ-elite-book:~/acme/rest-server> cat .gitignore build .project russ@russ-elite-book:~/acme/rest-server> git add . russ@russ-elite-book:~/acme/rest-server> git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached ..." to unstage) # # new file: .classpath # new file: .gitignore # new file: .project.sample # new file: .settings/.jsdtscope # new file: .settings/org.eclipse.jdt.core.prefs # new file: .settings/org.eclipse.wst.common.component # new file: .settings/org.eclipse.wst.common.project.facet.core.xml # new file: .settings/org.eclipse.wst.jsdt.ui.superType.container # new file: .settings/org.eclipse.wst.jsdt.ui.superType.name # new file: .settings/org.eclipse.wst.validation.prefs # new file: WebContent/META-INF/MANIFEST.MF # new file: WebContent/WEB-INF/web.xml # new file: lib/apache/commons-collections-3.1.jar # new file: lib/apache/commons-lang-2.6.jar # new file: lib/apache/log4j-1.2.16.jar # ... # new file: lib/jersey/asm-3.1.jar # new file: lib/jersey/jersey-client-1.6.jar # new file: lib/jersey/jersey-core-1.6.jar # new file: lib/jersey/jersey-json-1.6.jar # new file: lib/jersey/jersey-server-1.6.jar # ... # Java source files... # ... # new file: src/log4j.properties # ... # JUnit test files... # ... # russ@russ-elite-book:~/acme/rest-server> git commit . [master (root-commit) 8a1d194] Initial population of rest-server, second edition, the one we want to keep. 55 files changed, 1788 insertions(+), 0 deletions(-) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project.sample create mode 100644 .settings/.jsdtscope create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.wst.common.component create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.container create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.name create mode 100644 .settings/org.eclipse.wst.validation.prefs create mode 100644 WebContent/META-INF/MANIFEST.MF create mode 100644 WebContent/WEB-INF/web.xml create mode 100644 lib/apache/commons-collections-3.1.jar create mode 100644 lib/apache/commons-lang-2.6.jar create mode 100644 lib/apache/log4j-1.2.16.jar create mode 100644 ... create mode 100644 lib/jersey/asm-3.1.jar create mode 100644 lib/jersey/jersey-client-1.6.jar create mode 100644 lib/jersey/jersey-core-1.6.jar create mode 100644 lib/jersey/jersey-json-1.6.jar create mode 100644 lib/jersey/jersey-server-1.6.jar create mode 100644 ... create mode 100644 Java source files... create mode 100644 ... create mode 100644 src/log4j.properties create mode 100644 ... create mode 100644 JUnit test files... create mode 100644 ... russ@russ-elite-book:~/acme/rest-server> git branch -av * master 8a1d194 Initial population of rest-server, second editon, the one we want to keep. russ@russ-elite-book:~/acme/rest-server> git push origin master Counting objects: 80, done. Delta compression using up to 4 threads. Compressing objects: 100% (68/68), done. Writing objects: 100% (80/80), 9.36 MiB | 8.68 MiB/s, done. Total 80 (delta 2), reused 0 (delta 0) To [email protected]:rest-server * [new branch] master -> master

Here is the creation of branch jack and pushing it back to origin (remote).

russ@russ-elite-book:~/acme/rest-server> git checkout -b jack Switched to a new branch 'jack' russ@russ-elite-book:~/acme/rest-server> git branch * jack master russ@russ-elite-book:~/acme/rest-server> ls lib src test WebContent russ@russ-elite-book:~/acme/rest-server> git push Everything up-to-date russ@russ-elite-book:~/acme/rest-server> git branch -av * jack b241b4f Fixed partner id making it a string instead of an integer. Changes a symbol in User from staff to partner. Got all Partner JUnit tests running. master b241b4f Fixed partner id making it a string instead of an integer. Changes a symbol in User from staff to partner. Got all Partner JUnit tests running. remotes/origin/HEAD -> origin/master remotes/origin/master b241b4f Fixed partner id making it a string instead of an integer. Changes a symbol in User from staff to partner. Got all Partner JUnit tests running. russ@russ-elite-book:~/acme/rest-server> git push git@acme:rest-server jack Total 0 (delta 0), reused 0 (delta 0) To git@acme:rest-server * [new branch] jack -> jack

And we show that branch jack was truly pushed back to the remote and can be got again:

russ@russ-elite-book:~/acme/test> git clone git@acme:rest-server Initialized empty Git repository in /home/russ/acme/test/rest-server/.git/ remote: Counting objects: 121, done. remote: Compressing objects: 100% (96/96), done. remote: Total 121 (delta 18), reused 0 (delta 0) Receiving objects: 100% (121/121), 9.37 MiB | 7.79 MiB/s, done. Resolving deltas: 100% (18/18), done. russ@russ-elite-book:~/acme/test> cd rest-server/ russ@russ-elite-book:~/acme/test/rest-server> ls lib src test WebContent russ@russ-elite-book:~/acme/test/rest-server> git checkout jack Branch jack set up to track remote branch jack from origin. Switched to a new branch 'jack' russ@russ-elite-book:~/acme/test/rest-server> ls lib src test WebContent