Railgun is a spinoff of Index. The stories have overlap, but can be watched separately. Some of the overall story's context is clearer if you watch Index first, but there's nothing wrong with watching Railgun first.
For the Index/Railgun purist (fan) the suggested viewing order is Index 1, Railgun 1, Index 2, Railgun 2.
Hope this helps. :)