2

I have a question about using Git for a Java EE app on an IBM-AIX.

Nobody on my team (me included) has ever used a version control system.

If I install GIT for my Java EE app,

  1. I want the webapps directory to be tracked by Git version control.
  2. Do I make the webapps directory (which houses all the code) the server repository?
  3. Do I need to create a server repository elsewhere then create a project in that repository then check in/out files into that repository?
    This seems to be what is implied by some online tutorials, so I am confused about this part too.

Can anyone explain the best way to set up a Git repository and how local vs remote will work.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
david.colais
  • 619
  • 2
  • 7
  • 17

3 Answers3

1

In any version control system, there is a place that functions as a canonical representation of the history. In Git, that location can be flexible, but a common pattern is to use a hosting service such as GitHub to handle the hosting of the server repository.

Typically you would use a system like Maven or Gradle to handle building your webapp (as a war file, for example). This would mean you would check your src/main/java source tree into source control, and it would generate a war file as an output that you would push to your deployment areas.

Developers would use a "local" copy of the repository to make changes, commit them, and then push them to a central "remote" repository. Some other system (such as a continuous integration system like Jenkins) would be responsible for monitoring that remote repository for new changes and building that code into the artifact that you can then deploy to the field.

You can look at questions like Setting Git for a team of 3 people? to get an understanding of how to set up repositories in general.

Community
  • 1
  • 1
Emil Sit
  • 22,894
  • 7
  • 53
  • 75
  • I want to create the server repository in the development server.Currently what people are doing is they either use putty or tools such as win-scp to crete and update files.Say if I didn't want that form of editing for my webapps directory then how can I use GIT to safeguard this directory and what would creating a server repository mean in this case.As for as building the webapp is concerned i would worry about it after I'm done with setting up git. – david.colais Dec 26 '12 at 20:46
  • What workflow are you looking to have? That when someone runs `git push` it goes directly into your webapps directory? – Emil Sit Dec 27 '12 at 01:05
  • I havent installed git yet.I wanted to get th concept first.So do you mean to say that we can create something known as a workflow where the updates directly go to the webapps directory.Can you please elaborate. – david.colais Dec 27 '12 at 03:03
  • One of the "confusions" of Git is that it enables you to choose how you want the changes to flow through the system and into production. For example, see [some example workflows](http://git-scm.com/book/en/Distributed-Git-Distributed-Workflows). I recommended a sample pattern that is familiar to people using CVS but you can build a workflow that is more useful to your team if that one isn't good for you. – Emil Sit Dec 27 '12 at 15:43
0

I don't think you'll want to version-control the webapp directory on the server.

You should make a server repository (not mandatory for git, but may be easier to start with) in another server (not your production environment), so there will be your code. Then you should think about getting a Jenkins or something like that to handle compilation+deploys, and probably using Nexus to host different versions of your binaries.

Having all that together, Jenkins should be the responsible of building your source code to binaries, publishing them on Nexus, and deploying the new versions to the production environment.

mgarciaisaia
  • 14,521
  • 8
  • 57
  • 81
  • I want to create the server repository in the development server.Currently what people are doing is they either use putty or tools such as win-scp to crete and update files.Say if I didn't want that form of editing for my webapps directory then how can I use GIT to safeguard this directory and what would creating a server repository mean in this case.As for as building the webapp is concerned i would worry about it after I'm done with setting up git. – david.colais Dec 26 '12 at 20:47
0

You can create a git repository on the development server, but you wouldn't create it directly in your webapp directory.

You could create it anywhere else, and initialize it with a:

git --git-dir=/path/to/your/git/repo --work-tree=/path/to/webapp add .
git --git-dir=/path/to/your/git/repo --work-tree=/path/to/webapp commit -m "first import"

Then you would clone (still on the server) that git repo as a bare repo (to avoid synchronization issue with the working tree).

What you need to realize is that git itself doesn't listen to any remote query: you need to install a server (either the git daemon or ssh or https: see Git on the server).

Then, and only then your developers will be able to push to that bare git repo, and a post-receive hook will be able to update your webapps directory: see for instance "using git to deploy my node.js app to my production server", or "Git checkout in post-receive hook: “Not a git repository '.'".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for replying.So I need to create a bare git repository so that it links to the actual webapp directory?? So If I create a bare repository in this way will I be able to checkout the entire webapp directory to eclipse from this bare repo?? – david.colais Dec 27 '12 at 11:24
  • @david the bare repo is on the server side, for developers to push to, and for updating the webapps directory automatically. Eclipse, however, is on the client side, and would use the working tree of a non-bare repo, which would be the clone of the remote bare repo (git clone). Again, you need a listening service on the server side in order to listen to your git clone request. – VonC Dec 27 '12 at 12:03
  • So there is my webapp directory for which I create a bare repo inorder to directly push files from the server. And if I want to check out the files to a client say Eclipse would I be required to create a clone of the web-app directory or the bare repo which I have already created?? – david.colais Dec 27 '12 at 14:03
  • @david.colais The webapps directory I reference in my answer is the one on the server. It is on the server only you need a bare repo (to act as an intermediate between the developer's pushes, and the actual directory where the hook will checkout the content of said bare repo). All that is server-side. On client side (on your workstation), if you already have a local webapps directory, you can initialize a git repo directly in it, in order to initiate the process. In that case, you would push to an *empty* bare repo that you would have first created on the server. – VonC Dec 27 '12 at 14:12
  • @david.colais you push files from clients (developer's workstations local clone) to one bare repo on the server. And that bare repo has a hook which will update the final webapps directory on the server. – VonC Dec 27 '12 at 14:13
  • Say If on the client side in Eclipse if I dont have the local copy of webapps directory then what would I be required to do in order to get the copy of the webapps directory in the unix server.I dont know which part I'm not getting. I understood the purpose of the bare repo after that I'm abit confused. – david.colais Dec 27 '12 at 14:17
  • @david.colais the question is: where currently do you *have* that webapps directory? On a local project in an Eclipse on your local workstation? Or on your server only? – VonC Dec 27 '12 at 14:19
  • @david.colais if you have it on the server only, my initial answer stands (create a git repo on the server outside of the `webapps`, then `clone --bare` that repo, still on the server, add a hook to that bare repo, and local `clone` that bare repo on your workstation, where your Eclipse project can reference it). – VonC Dec 27 '12 at 14:21
  • The webapps directory is present only in the unix server. Your previous suggestion holds good.BTW how does one local clone that bare repo on your workstation i.e on windows where the eclipse in installed. – david.colais Dec 27 '12 at 15:35
  • @david.colais that is where the listener service comes in play. You need ssh (http://www.mindfuzz.net/?p=250 or http://www.fclose.com/b/linux/366/set-up-git-server-through-ssh-connection/) or https (http://sourcevirtues.wordpress.com/2012/03/04/setup-git-server-with-https-on-debian-stable/) to listen to your client git command (like a `git clone`). Or you can just use the git daemon packaged with git (http://git-scm.com/book/ch4-9.html). The two first methods allows for authentication if you need it, the last one does not. – VonC Dec 27 '12 at 16:29
  • @david.colais For *authorization*, you would add (to an ssh or https server) an authorization layer like Gitolite (http://stackoverflow.com/a/13320256/6309). But only if you need to control who access what. – VonC Dec 27 '12 at 16:31