Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Git, BitBucket and LocalServer

I'm a bit of a noob when it comes to Git so any help here would be superb.

I'm using Git on my Mac local to save versions of coding as I move along. I am also using the awesome BitBucket service to store significant changes. Along with this I use a local Mac for a testing server along with the obvious ftp servers.

So.....

I at the moment I can... commit locally, push to bitbucket but I need to know how to then send just the build directory to the local server to test at certain times and when that is all groovy, send over to a live server.

I'm stumped.

I know there are hooks but I'm clueless on this. If someone can point me in the general right direction so I'm at least looking under the right stones, that would be great.

Thank you :)

7 Answers

Nick Pettit
STAFF
Nick Pettit
Treehouse Teacher

Hey Suleiman,

I've pinged a few of our dev teachers to see if they can help you out. :)

Thanks Nick, really appreciated :)

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Suleiman,

Git hooks are just shell scrips inside of your .git/hooks directory in your project. You should find sample files there that happen during the different parts of your project's life cycle. You may want to use the post-commit hook to accomplish this. You can find more information in the following git documentation:

http://www.kernel.org/pub/software/scm/git/docs/githooks.html

Jim Hoskins
STAFF
Jim Hoskins
Treehouse Guest Teacher

So, I'm not sure I fully understand. Is your local server separate from your development environment? Do you have git installed on your local and development servers?

Anyways, git does various hooks that can be run before and after things like commits, pushes, receiving pushes, etc.. These are basic shell scripts that could do anything. The issue is, since you're on Bitbucket (this applies as well to Github and other hosted git providers), you can't just write those scripts.

You could, if you have ssh access to your various servers, set up additional clones on those servers, and add them as remotes to your development repo.

git remote add localserver ssh://user@localserver:/path/to/repo

Then you could push to those servers directly

git push localserver master

Then you could have the various hooks (http://git-scm.com/book/en/Customizing-Git-Git-Hooks) to copy files around as needed.

If you can't do that, the communicating from bitbucket/github to your servers is possible (as long as the servers are addressable) via POST hooks https://confluence.atlassian.com/display/BITBUCKET/POST+Service+Management

Basically this means bitbucket will send a post request when it receives a push, and the script in your server that handles it can update code as needed. Be careful with this method, if someone else finds the URL for it, they could trigger updates. It's not an ideal solution for me.

Ultimately, you are looking for a deployment solution, which git is not. Git helps and can be a basis for your deploy process, but it's still up to you. There are tools such as capistrano which may be more than you need. It's typically used for provisioning and deploying rails environments, but it can do basic file transfers. Older free railscast video or Newer railscast pro video

It's not a simple question to answer, because everybody's setup is different. Welcome to the exciting world of devops

Dagnamit, that is a bloody fine response. Thank you Jim!!

Jason, thank you I didn't know about that directory and it explains a great deal to me now. It seems there is a light at the end of this tunnel after all :)