I am a php developer. I have installed Git on my system(ubuntu 12.04). Now i want to make my system as server and my colleague's systems as clients. ie, a local sharing. Is it possible? we are using eclipse as the editor. We have installed the EGIT plugin in our system. I am very new in Git.Please help me.
Run git daemon to serve your local git repository:
$ git daemon --export-all --base-path=$(pwd)
.. assuming pwd path is at your git repository..
Then others can either clone your repository or just pull from it if they already have the same repository cloned from a common origin:
e.g.
git remote add yourname git://your-ip-address/repo-name
git pull yourname master
First, you need a static local IP address on the server (or a local DNS hostname.) Let's suppose you have a static local ip of 192.168.1.23
Next your colleagues need to have permission to access /home/user/Project. The simplest way is to do this (on the server):
adduser gituser
chown -R gituser /home/user/Project
Now everything in your repo is owned by gituser. Give the password for gituser to your colleagues.
Next, on the client(s), run
git clone gituser#192.168.1.23:/home/user/Project
This should create a copy of your repo on the client.
As for EGit, I recommend leaving that aside until you are more experienced with using Git on the command line. Egit may be easier to use once you understand it, but it is NOT easier to learn.
Related
I want to use GIT in my project. Right now, i download file from FTP server and then upload it after updating the code. I want to use GIT where i download entire code from server and then through commit and push it goes to server. I don't want use some git application that support FTP but actual GIT. How i can achieve this. Thanks.
Due to you already having an existing code base i will be telling you how to add to a repository.
To use git you will need a repository service like Github or Gitlab. Make sure you have an account and create a repository for your project.
Once you have git installed open a command line in the folder
Git init
This will initialize the folder for git, you may have notice a .git file appear in your ide. This hidden folder is the configuration. Depending on the operating system the instructions may be different.
Open a command line terminal in your directory and enter
git config --global user.name “Your Git Repository Username”
git config --global user.email “Your Git Repository Email Address”
Next you will do
Git add .
This will tell git to prepare all of the files in the existing folder.
Git remote add origin “Your git Repository link ending in a .git”
This will tell git to where it is going to upload (push) the files to, i have told it in this command to call the branch(branches are a version you can work in, you could have a beta version, stable etc) origin.
Git commit -m “These are notes for the repository”
This will add notes to the push, normally comment on what has been changed.
Git push
You will be asked to login to GIT to verify the git installation.
This will push/upload the contents of the folder, make sure you have nothing that is personal in this code because unless you have set the repo to private then it will be public by default on most platforms. It will never push the .git folder.
Ok so when you want to download from a repo its best to again setup git via the Git init & git remote add commands
Then you are able to
Git pull origin master
I hope this helped, any questions i will be around to answer them.
I'm new with git and still a bit confused how to best manage a local repository with a webserver. Until now, I've just used a plain text editor and FileZilla to upload HTML and PHP code to webserver.
Now I would like to use git for versioning and I've created a local repository on my Ubuntu desktop and made some changes to my code. Do I still have to use FileZilla to upload code to webserver or is there a more comfortable way with a git command? - All I found on the web was to use push and pull, but only in conjunction with GitHub - since I don't need to share my code it with others, I don't want to make my code public on GitHub.
Is there a git command to upload commited HTML and PHP files to webserver? Or have I misunderstood something? - Or shall I think about it that my repository is the code on the webserver?
Any help welcome.
Have you git installed on your server?
Push your code to your account repository on GitHub / Gitlab or Bitbucket
2.In your html_public directory, run these commands
To initialize git in the folder
git init
To add your main remote where you will pull / push etc your code
git remote add origin https://your_remote_url.git
Recover the remote code
git pull origin the_branch_you_want_to_recover
or
git clone https://your_remote_url.git
or
git clone -u https://your_remote_url.git the_branch_you_want_to_recover
After intensive research today, I found git-ftp and I think that this add-on is exactly what I was looking for.
I want to upgrade my website without downtime. I made researches and didn't find a way to upgrade it without downtime (few seconds are fine). I was thinking a way as follows, but I am not sure whether any good professional way is there. Please help me out on how to improve this.
Add new tables/CFs to the database (database is Cassandra,
we are not supposed to do any changes in existing tables/CF)
Deploy the project in online server in different Directory, so that
users can still use the existing site.
Point the uploaded project in different port and check whether
everything is working properly.
If everything is working change the symlink to the uploaded directory
Please let me know any other good methodology if you have.
I am using SVN in my local server
UPDATING THE SERVER ALMOST INSTANTANEOUSLY
Ok for this one of the best and the easiest method is using Git. So, what you should do is host your code in Git and then whenever you want to update the site, just SSH into the server and do a Git Pull. It's instantaneous and it would update it. Also you can use Git Hooks to further solve your problem as well.
There are a few ways you can go about it, but one of the easier methods would be this.
Let me explain it in detail on how to do it:
The source for your web site should live in a Git repository on the local workstation. I shall describe how I set things up so that I can make changes live by running just "git push online".
The local repository
It doesn't really matter how the local repository is set up, but for the sake of argument, let's suppose you're starting one from scratch.
$ mkdir somesite && cd somesite
$ git init
Initialized empty Git repository in /home/sankalpsingha/somesite/.git/
$ echo 'Test!' > index.html
$ git add index.html
$ git commit -q -m "This is the first push."
The remote repository
I assume that the web site will live on a server to which you have ssh access, and that things are set up so that you can ssh to it without having to type a password (i.e., that your public key is in ~/.ssh/authorized_keys and you are running ssh-agent locally).
On the server, we create a new repository to mirror the local one.
$ mkdir coolsite.git && cd coolsite.git
$ git init --bare
Initialized empty Git repository in /home/sankalpsingha/coolsite.git/
Now lets make and define the hoolks as a post-receive hook that checks out the latest tree into the web server's DocumentRoot (this directory must exist; Git will not create it for you):
$ mkdir /var/www/www.somesite.org
$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/www.somesite.org git checkout -f
$ chmod +x hooks/post-receive
Back on the workstation, we define a name for the remote mirror, and then mirror to it, creating a new "master" branch there.
$ git remote add online ssh://server.somesite.org/home/sankalpsingha/coolsite.git
$ git push online +master:refs/heads/master
On the server, /var/www/www.somesite.org should now contain a copy of your files, independent of any .git metadata.
The update process
Just run :
$ git push online
This will transfer any new commits to the remote repository, where the post-receive hook will immediately update the DocumentRoot for you.
(This is more convenient than defining your workstation as a remote on the server, and running "git pull" by hand or from a cron job, and it doesn't require your workstation to be accessible by ssh.)
You can use some CI or deployment tools. I'm doing this manually. Here is the way i'm doing it.
I have a workcopy directory from git, and git hook to sync it on push.
Then i sync worckopy directory with site using rsync.
All database changes done with migrations, so 1 command yiic migrate is enough to make new tables or alter existing.
With this methodology there is no actuall downtime, some pages can be unavailable for 5-10 sec max, but all system works on this time.
Point the uploaded project in different port and check whether
everything is working properly. If everything is working change the
symlink to the uploaded directory
It's bad way, for testing you need test server, or test it on local machine with same configs and params as on server. For example Vagrant can make any environment on your local machine for testing.
If you need to pass tests (e.g. unit tests or functional), then watch on CI tools.
I have decided that it's time for me to start using Git on a PHP project that I have been developing casually for over a decade. (Please, no lectures from the version control police!) Due to the complex setup required on my VPS to do everything the project needs (esp. single-codebase-multiple-client structure and a Japanese-capable installation of TeX to create specialty PDFs), it is not possible to set up a development environment on my local Windows box. But I do have a testbed area on the server that I can play in, so it's my development area. Currently I use Filezilla to access the server and open files directly into Notepad++, and when I'm ready to see my edit in action, I just save and let Filezilla upload. When everything looks good on the testbed, I copy the files to the production codebase area. Yeah, that gives me no history of my changes other than my own comments, and I have to be careful not to mix bug fixes with half-finished new features. I can see the value of Git's branches for different upgrades in progress.
Yesterday I got my toes wet. First I created a Github account, and then (at the recommendation of a tutorial) installed Git For Windows (with its own Bash and tiny-looking GUI) and Kdiff3, and followed some instructions for configuring Git Bash. After all that, though, I ended up having to install something else in order to interface with my Github account (appropriately named Github for Windows), which seem to do all the stuff the other two programs were supposed to do for me. Anyway, then I did a simple task as my first foray into the Github world - I had added functionality to someone else's jQuery plugin and wanted to share it with the developer, so I forked his repo, cloned it to my machine, overwrote the file I had previously edited and tested, synced to my Github account, and sent a pull request. All the terminology in that last sentence was brand new to me, so I was pretty proud of myself that I got that far. ;) But I guess I only needed the Github software, not the Git software - it's hard to know what tutorials to believe.
Anyway, now I want to figure out a workflow for my own stuff, which is my actual question for you guys. From what I can tell, having the master repo anywhere but the public Github costs money, and I don't care if others see my code (I don't expect anyone else to work on my oddball project made of spaghetti code, but if they want to, that's great). Okay, but then what? Perhaps one of these scenarios, or something else:
Clone branches of the repo to my PC, do edits on the local files, and upload them in Filezilla for testing (a couple more clicks than my current workflow because Filezilla doesn't automatically see the relationship between the local file and the remote file, but not a big deal). Then when I'm happy with the code, commit locally, sync to Github, and copy the files (from somewhere - not sure on this point) to the production area.
Install the Linux flavor of Git on my VPS so that the "local" Git file location is the testbed, and use Git through PuTTY to do the local commits. Simpler for file structure (no need for a copy on my PC at all) but more cumbersome to use Git:
I'm not on PuTTY very frequently, and for some reason the connection often dies on me and I have to restart.
Even though the Linux command line is Git's native habitat, I am probably more comfortable with a GUI (because I forget command syntax quickly - old brain, I guess).
Also, since I never ended up using the Git program I installed here, I'm not sure whether it would be Git or Github I would be using on the server.
Some other scenario, since neither #1 or #2 uses Git/Github to manage the production file area at all, which would probably be a good idea so that I don't forget to copy everything I need.
I tried to research the possibility of a PHP-based GUI to go with idea #2 (so I don't have to use PuTTY for day-to-day operations), but it seems that the discussions of such tools all assume either that you are trying to create your own Github service, or that the "local" cloned repo is physically on your local PC (with xAMP running on whatever OS it is). But maybe the Github software I used is enough to do all that - it's hard to tell. I don't yet understand the interplay between a master public repo on Github, branches somewhere (on Github also?), at least two sets of files on my web server (the testbed and the production area), Github software, Git software, and the keyboard/screen of the computer I'm sitting at.
So pardon my newbie ramblings, but if someone out there has a similar development situation, What's your workflow? Or what would you suggest for me?
Here's one way to aproach the issue:
You will need three repositories:
a local repo to edit code. [1]
a bare remote repository on your server. This will be in a location that in not publicly viewable, but you can ssh in to. [2]
The production environment. [3]
Here's the implementation:
workstation$ cd localWorkingDirectory/
workstation$ git init
workstation$ git add .
workstation$ git commit -m 'initial commit'
workstation$ ssh login#myserver
myserver$ mkdir myrepo.git
myserver$ cd myrepo.git
myserver$ git init --bare
myserver$ exit
workstation$ cd localWorkingDirectory/
workstation$ git remote add origin login#myserver:myrepo.git
workstation$ git push origin master
every time you make a commit on any branch, back it up with:
workstation$ git push origin BRANCH
When you are ready to move branch version2 into production: do this
workstation$ git push origin version2
workstation$ ssh login#myserver
myserver$ git clone path/to/myrepo.git productionDirectory
myserver$ cd productionDirectory
myserver$ git checkout version2
Oh no! It dsoesn't work! better switch back to version1!
workstation$ ssh login#myserver
myserver$ cd productionDirectory
myserver$ git checkout version1
You don't need github (or any other central store) to start using git. Especially since you're a lone developer. Git runs directly on your own machine, without any server component (unlike for example subversion). Just git init and start committing away.
I agree with the other commenters here, that you should aim to get a local development environment up and running. Even if it takes some effort, it's certainly worth it. One of the side effects of doing so may be that you are forced to decouple some of your current hard dependencies and thereby getting a better overall application architecture out of it. The things that can't easily be replicated in your development environment could instead be replaced with mock services.
Once that is in place, look into a scripted deployment process. E.g. write a shell script that syncs your development machine's codebase with the production server. There are many ways to do this, but I suggest you start really simple, then revise your options (Capistrano is one option).
I'd certainly look at something like capistrano for your current development setup.
I can understand why you might have a reticence to use the terminal but it would probably help your understanding of git in context. Doesn't take long to get to grips with the commands and when tied into a system such as capistrano you'll be rocking development code up to your environment in no time:
git commit -a
git push origin develop
cap deploy:dev
When i'm working on windows i generally try to replicate the deployment environment i have with virtual machines locally using something like sun's virtualbox. That way you can minimise potential environment issues while still developing locally. Then you can just use putty to ssh to your local vm. Setup sharing between the vm and your host OS and all your standard IDEs/editors will work too. I find this preferable to having to setup a vps remotely but whatever works.
I have a webserver setup using the standard linux, apache, mysql, php config and I currently don't have a way of doing revision control - I just backup the whole thing every now and then. I'd like to set up a github repository for just the php and html files - basically everything in public_html. Not really sure where to get started or how to approach it... I guess I could just set up a git repository in the public_html folder itself but that doesn't seem ideal...
Set up a Git repository one level above public_html ( git init; git commit -a ). Simple and easy (Git only creates one folder wherever you create it); you don't need to use Github (which is a publicly accessible Git repository).