A class of hierarchically porous carbons were prepared by a facile dual-templating approach. The obtained samples were characterized by scanning electron microscopy, X-ray diffraction, Raman spectroscopy, Brunaner-Emmett-Teller measurement and electrochemical work station, respectively. The porous carbons could possess large specific surface area, interconnected pore structures, high conductivity and graphitizing degree. The resulting materials were used to prepare integrated modified electrodes. Based on the experimental results, the as-prepared hierarchically porous graphite (HPG) modified electrode showed the best electroactive performances toward the detection of nitrite with a detection limit of 8.1 × 10-3 mM. This HPG electrode was also repeatable and stable for 6 weeks. Moreover, this electrode was used for the determination of nitrite in drinkable water, and had acceptable recoveries. © The Royal Society of Chemistry 2016.