I'm trying to learn how to use Git in my daily workflow but I'm slightly confused as to how to make it work for me. As a web developer, the way I work is that I have two VPS' - one as a production and the other as a development server. On the development server, I usually create a webdav that points to the source files (located in /home/public_html/dev.domain.co.uk/) and mount it as a local folder on my mac. This way, I can open (or create) the PHP files in my IDE, do what I need to, save the file and then refresh the test link in my browser.
Now, as I say, I would like to start using Git to keep track of all amends I, and my co-workers, make to projects. So my question is how would I do this - would I create a repository on my development server in the public_html folder? And when I clone the repository on the different machines I work on, would I mount the webdav and clone the repository in there? Ideally I want to set up an online repo that myself and co-workers can access.
Any help and/or advice would be much appreciated.
Thanks :)
I have a similar workflow. I was using my IDE to edit the files over SSH, effectively using the files directly on a development server. What I ended up doing was opening a console over SSH to my dev server, and running git there. I use Bitbucket as a remote, and push/pull from there, keeping all of my changes somewhat centralized. What I need to push to my production server, I pull from Bitbucket, and then flip a symlink so that all files appear updated instantaneously.
Git is a decentralized version control system, meaning that you do not need to have a "shared" repository. However, when collaborating, especially if you do not work closely with your coworkers, it might be attractive to have a central point with an "official" repository.
Now in your case, if you want to continue working in your WebDAV exported folder on your testing machine, it depends on if you share this folder with coworkers or not. If it's your private working space, create your git repository there and work with it however you like.
To setup a central, "official" repository you push you changes to, you have several choices depending on your infrastructure:
Use a 3rd party service like GitHub or BitBucket: This is simple to setup and use, but may require subscription fees if you want to keep your repository private.
Use your development server and setup a clone of your repository in a shared place, either via SSH or WebDAV. This might require more maintenance and you don't get the fancy WebUI of GitHub and the likes.
You might also want to have a look at this article about a branching model for development.
You could use a service like http://bitbucket.org.
it's free and it allows to create private and public repositories.
Once you commit changes, simply push it to the server (they tell you how to do it), then have your partner to clone that repository and pull from it whenever necessary.
Related
In my project the deployable version needs to have a copy of each of the external libs, a different config file and install and setup files, for security concerns, the main project is set to refuse to run if they are present. Thus the upstream copies of the other projects need to be committed to repo. How can I work on code running on localhost where the file layout and sometimes file contents from dev and testing are different to what I need to commit?
Background
I am working on a project on hosted on github and my main IDE is netbeans which has imperfect git support (good enough for >99% of my needs). The project is in PHP and uses several other projects as libraries.
As Netbeans does not have the best support for sub-repos I have chosen to keep each additional project in a separate project. This is fine as the central project looks at the config data for where to find these outside libs.
Half an answer
My instinct is to suppose that there will need to be some "build stage" prior to committing to the github repo but how on earth do I go about setting all that up?
I could write some sort of homebrew thing but then when I pull other people's contributions I would need to reverse the process unless we had a branch for builds and a branch for working copies which seems needlessly complex and could leave the dev(s) config data on public display (not to mention updates being a mess).
I have seen that others have wrestled with somewhat similar problems to no conclusion (at time of asking) (How to push and pull from github without sharing sensitive information? Smudge & clean?) so I am looking for anything that might help me come up with a solution
my main IDE is netbeans which has imperfect git support
Most devs just use the command line. I switch to the NetBeans conflict resolver occasionally, which is very good, but for normal stuff the console is usually faster.
My instinct is to suppose that there will need to be some "build stage" prior to committing to the github repo
... unless we had a branch for builds and a branch for working copies
No, there is only ever one repository. It is better to think of your repo as your code history, rather than your deployment state. Branches should just be for features or large changes, which merge into your mainline/master.
There are a good deal of options available to you when deploying. The first is Composer, which Mark points out: when deploying you issue an install or update command, which fetches the dependencies that satisfy your library requirements recursively. You can use Bower to do the same thing for your JavaScript dependencies.
Some deployment strategies prefer to build locally and then scp/rsync to a remote server. Composer and Bower are still probably a good idea, but you write a build script (using Ant or Phing, for example) to create a build copy in a local temporary folder, and then send it to the server. It is common here also to push it to a new release folder on the server, and then swap a symlink or Apache config file when it's ready to go live.
the deployable version needs to have a copy of each of the external libs, a different config file and install and setup files, for security concerns
Assuming this is a web project, have you tried adding your sensitive environment data to your Apache configuration file? This can be trivially read in PHP, and of course PHP does not care that this information is different according to whether you are developing, testing, demoing a branch or operating live.
Further reading: an excellent PHP deployment book, free of charge, that suggests Phing and Capistrano.
I had just implemented GIT Version Control for a Team of three people. We are managing to pull/push/fetch etc to our bitBucket repository. My only concern is how I should push live after we make an update to the repository.
On another server, I wrote a shell script to clone the repo into a directory so I would be able to test, but on the live server I cannot do the same since on some occasions I just have to push one file only.
Please note that our live server is inside a network and not accessible over the internet (thus I cannot use BitBucket's push service).
The only advise I can give is to make sure that the local repository (which concentrates changes from the developers) is up to date and in shape before pushing.
Locally you can define your workflow. Perhaps the master repo, into which only official commits are taken, branches for each developer's work once it passes local tests, and each one does as they please on their machines. Or something fancier. There are suggestions on workflows, ranging from almost centralized to completely distributed, check them out. If you adopt one way of working, git won't stand in your way if you decide later to change it.
I am an avid webdev hobbyist and freelance, up until now I simply edit the website live (put a maintenance message up while its being made), now all my projects up until now have also been very small.
eg I make a site, show em, take money and go, I've never had to work on a site after it's gone live.
Now my new project is pretty big and I know I will have to edit it after its gone live and maybe have a small team of devs (atm just me)
So how do people professionally handle this? I know I will need a prefix-amp app cos i run an apache server, I've also heared that people use github for versioning, but I'm not really sure because apparently its not svn?
Thanks
ps. I have a windows 7 pc, so no mac apps please
up until now i simply edit the website live
Terrible in my book ;)
so how do people professionally handle this?
First you need to setup a development server (it would be best to keep it as close as possible to the expected live environments). On this server you would install all the software you need.
You may also want to setup a staging server.
i know i will need a prefix-amp app
I hope you are not talking about those one click installers. If you would do it professionally you should install everything yourself that way you can set it up the way you need it.
ive also heared that people use github for versioning, but im not really sure because apparently its not svn?
GitHub is just a website. What you are looking for is git or svn for versioning. You could also setup a git or svn server locally instead of using services like GitHub. Basically what versioning is is that when somebody makes a change to the code he/she would need commit the changes. This way it is easy to keep track of changes in the codebase (like what was changed, when was it changed and by whom).
Local XAMP-stack (LAMP, or WAMP) for development
intranet-system for test and maybe staging
Of course the live system
Versioncontrol, I prefer git. Of course you can use SVN too, but... lets say: It's SVN.
Make changes local, test this changes local
everythings fine: Push it into the "master" vcs-repository
New version ready (or it's "sunday-night-release-time")? Push all that stuff on test/stage
Everythings fine there too: Push it into the live system
Thats very shortened of course, but it should give you an idea.
The tool where you manage your software version is not that important. Use Git, or SVN or whatever, the one you like most. But use _one_.
Equally important is that you run the "page" on two sites, a test and a live system, strictly apart. Both systems have to be very close in their layout, all changes must first be done in the test system, be verified and then done in the same manner in the live system. Do not allow changes only to be made to the live system ('cause it's just a small change'). No exceptions.
Then think about deployment: how will you transfer changed files to the target system ? You need routines for this, that run once started and don't forget a step in between.
Firstly you need some kind of versioning system: either SVN or Git. GitHub is simply an online service that provides managed Git repositories. Secondly you need a development server.
If it were just you doing development, you could host both of these on your local desktop PC, but since other developers are going to be joining, you need a remote server. If you don't want to be running a server out of your home, the best option is a VPS (virtual private server) on which you can install Git, Apache, etc. and anything else you need.
As for development software, take your pick- there are loads of options. A common choice is the NetBeans IDE and TortoiseGit combo. You use NetBeans to develop your code on, automatically uploading to your development server, then you TortoiseGit to commit and sync changes.
Only when you're ready to go live do you copy the code from the dev server to the production server.
Before I begin, I know there are a lot of questions similar to this one, but I am really having difficulty finding a concise, secure, best practice since the feedback on them has been so widely varied.
What I want to do:
Complete work on my local machine on a development branch.
Push changes to git. Git posts to a webhook URL and automatically has my remote server pull the changes on a development site.
Once QA'd and confirmed to be proper on the development site, push the master branch to the production site (on the same server as the development site).
Where I am at:
I have git installed on my local machine and the remote server. I can push mods to the development branch to git. On the remote server, I can pull the updates and it works like a charm. The problem is that I cannot get the remote server to automatically update when changes are pushed from my local machine.
My questions are:
For the remote server development site directory, should I git init or git init --bare? I don't plan on having updates made on the server itself. I would like my dev team to work locally and push mods to the server. I believe I need to use git init as the working tree is needed to set-up a remote alias to the git repository, but I wanted to confirm.
I am pretty sure the webhook post from git issue is due to user privileges. How can I safely get around this? I have read many tutorials that suggest updating git hook files, but I feel as though that is more drastic of a measure than I need to take. I would love to be able to have the webhook hit a URL that safely pulls the files without adding a boatload of code (if it is possible).
I am a web developer by nature, so git and sysadmin tasks are generally the bane of my existence. Again, I know this question is similar to others, but I have yet to find a comprehensive, concise, secure, and most logical approach to resolving the issue. I am about 16 hours in and have officially hit the "going in circles with no progress" point.
You can do this quite easily with GitHub service hooks.
You ll need to create one more file that will handle the process of performing the git pull. Add a new file, called github.php (or anything you wish ), and add:
<?php `git pull`;
Save that file, and upload it to the repository directory on your server. Then, go to Services Hooks -> Post-Receive URL and copy the URL to that file, and paste it into the “Post-Receive URL” E.g. http://demo.test.com/myfolder/github.php
So, when you push, GitHub will automatically visit this URL, thus causing your server to perform a git pull.
To see this in more details to go to this tutorial
I had the same exact issue, strong in code and development skills, weak in sysadmin skills. When I was finally ready to push code I had to ask a GitHub rep what their suggested method was, and they responded with Capistrano. It's a Ruby application that runs commands (such as git pull) on remote servers, along with pretty much any other command you can imagine.
Here a few articles you can read to get more info:
GitHub - Deploy with Capistrano
How to compile the Capistrano stack on your *nix system
Another example of how to deploy code with Capistrano
Not going to lie, the learning curve was pretty steep, but once you start working with Capistrano, you will see that it works well for pushing code. I develop my applications in Symfony and I have my Capistrano set-up to pull code, clear cache and clear log files, all in one command from my local machine.
I code all by myself, and I have 1 website . but i dont ever use subversion or github. Question is:
How to develop on souce code of my website server and update it when develop complete.
In this case , should use github or subversion.
Truthly , i read and using github then try to create repository but anyone can watch mycode . I dont want that.
I want 1 guide easy for very begin about this.
You can use Git locally. So no need for Github. There is a video serie on www.tekpub.com about Git.
SVN and GIT are two completely different types of code repository patterns. If you using GIT you don't need a central server and can create a repository locally on your machine. I recommend you get familiar with this website just to get a basic overview of what a DVCS is and how it can affect the way you code.
HgInit
The good news is that you aren't familiar with any VCS (I assume) and that means you won't get mixed up when trying to learn GIT coming from SVN.
Assuming you already know the basics of how to commit/push/etc with git, which your answer suggests you do, the problem is that your repo is set to be public and not private. You can change this on the repo's admin page, assuming your github account has enough private repos left (The lowest account level that supports this is USD$7/month iirc). There are other git hosts which you can use for free that provide private repos.
As Roger said, you can use Git locally and do not need a server for that.
For SVN you need a central repository server, that usually does not correspond to your live webserver.
You will need a running Apache server and install SVN as an additional module for it. Once you have a subversion server running, you can then add repositories to it, normally one repository per project.
Usually you would have a local subversion installation on a development server in your local network or even (as you work alone) on your local machine, using a distinct host/port configuration for SVN, e.g. you could use localhost:80 for your development of the live website, and localhost:9999 for your SVN installation. There are several guides for installing SVN on Windows, Linux and MacOS found via google.
Both version control systems require some initial work to get it, but I personally prefer Git over SVN. Check out the Git guide on stackoverflow or the SVN book.
Personally, I find SVN easier to learn and install than GIT (but I guess that depends on person ;) and OS - I'm on windows unfortunately)
That's why I choose some free personal host for that. I tried BeanStalk and XP-Dev. The first one, is cleaner and much more user-friendly... and offer GIT or SVn ! But you got only 1 personal project available for free.
The second one is ugly but quite performant, 2 personal projects but only with SVN for free.