Take the 2-minute tour ×

I'm new to both maven and git and wanted to get some help in setting a project.

Is there a way to define a goal in the pom to push/pull from git during linked to a maven phase? For example, can I pull from git during the maven install phase?

If yes, how can that be accomplished? I would appreciate any code examples.

share|improve this question
Why would you like to push or pull during a build? Sounds like a really bad idea. –  Stein G. Strindhaug Jun 15 '11 at 14:32
It's not really a build. The project contains automated tests. And the way our test framework is setup we need to pull the latest framework code to run the tests from time to time. –  user786045 Jun 15 '11 at 14:41
Assuming the pull will fast-forward (no merge resolution needed), isn't just running "git pull repoName" then "mvn arguments" simple enough? If it may not fast forward, how should maven handle it? –  Stein G. Strindhaug Jun 15 '11 at 14:46
add comment

3 Answers

up vote 5 down vote accepted

Good idea or not, here's how you could do a checkout (pull clone from Github) using Maven. Have your pom.xml look like this:


<name>engesoft Maven Webapp</name>


Then use mvn scm:checkout. When I ran this, it pulled the code to folder target/engesoft. There's probably a way to configure it to place it somewhere else. Check out the following pages:

share|improve this answer
Where do you specify the git password? –  Nandish A Mar 15 '13 at 9:46
I use SSH keys instead of password. See help.github.com/articles/generating-ssh-keys –  Vítor E. Silva Souza Apr 14 '13 at 14:11
add comment

Instead of doing this during the Maven build, use a CI server like Jenkins. It will do the git pull before running maven, so the build tool can concentrate on it's main purpose: Building source code.

This also makes it more simple for you to develop since pull's will only happen when you want them. If you pull all the time, another developer can change something and you will get errors that you don't expect.

share|improve this answer
add comment

The scm:checkout goal Vitor is referring to is a clone, not a pull (huge difference in Git).

I had to use the exec goal to do what you're describing. I also didn't want to do an entire clone each time there was a build. Instead, I use git reset --hard and then pull -f origin Release:Release (via exec).

If I find a better way (and there HAS to be one) I'll post it here.

share|improve this answer
Thanks for the clarification. I'm still a git newbie. –  Vítor E. Silva Souza Apr 14 '13 at 14:11
add comment

Your Answer


