Since your homeland is invaded you have any right to defend it any way you can. However, in order to be treated by the Geneva Convention as a part of the armed forces of a nation (or country) you are required to : bear your armament publicly (not concealed), bear a sign or a mark that signifies you follow a specific leader, respect the rules of war.

If all of the above are met, then you are (by the Geneva Convention) part of your country's defence forces and in case you are captured you must be treated as a soldier.

If you pull out a concealed weapon and start shooting anything that passes by, then you are considered as a terrorist and treated as such.

So, if your country is invaded, join the official defence forces or form a militia and follow the orders of a very specific leader that is under the command of the leader (president, prime-minister, king etc) of your nation (- country).

Source: QUORA