Ideally a dedicated decoration could be used (similar to the one that the mindmap
library provides for connecting concepts), but here is a simple example using the show path construction
decoration.
The shading is applied manually to (a) illustrate how it can be done (b) bypass the default process of clipping the shading to the center quarter.
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\colorlet{bar.top}{red}
\colorlet{bar.bottom}{blue}
\pgfdeclareverticalshading[bar.top,bar.bottom]{shaded.bar}{100bp}{
color(0bp)=(bar.bottom);color(100bp)=(bar.top)}
\tikzset{shading bar/.style args={#1 thick from #2 to #3}{
decoration={show path construction,
lineto code={
\pgfscope%
%
% Set the colors.
\colorlet{bar.top}{#2}%
\colorlet{bar.bottom}{#3}%
%
% Manually apply the shading.
% As the bar is a rectangle, scale the shading (which is 100bp x 100bp).
% Other bar shapes would other adjustments before applying the shading.
\pgftransformshift{\pgfpointdecoratedinputsegmentfirst}%
\pgftransformrotate{\pgfdecoratedangle}%
\pgftransformxscale{\pgfdecoratedinputsegmentlength/100bp}%
\pgftransformyscale{#1/100bp}%
%
% Although the shading is a (scaled) rectangle the
% bounding box needs to be updated to the correct size
% which is done here using clipping.
\pgfpathrectangle{\pgfqpoint{0bp}{-50bp}}{\pgfqpoint{100bp}{100bp}}%
\pgfusepath{clip}%
\pgftransformshift{\pgfqpoint{50bp}{0bp}}%
\pgflowlevelsynccm%
\pgfuseshading{shaded.bar}%
\endpgfscope%
}}, decorate
}}
\begin{document}
\begin{tikzpicture}
\draw (0,0) grid (5,5);
\draw [shading bar=5mm thick from red to orange] (0,0) -- (3,2);
\draw [shading bar=5mm thick from blue to cyan] (0,2) -- (2,5);
\draw [shading bar=10mm thick from green to yellow] (3,5) -- (5,0);
\end{tikzpicture}
\end{document}