There's often a bit of confusion about this.
First of all, this might help:
One of the main reasons for confusion is because there's muddling between political names (names of countries) and geographical terms (names of places).
Here political names are in blue and geographical terms are in red

Note: the term "Republic of Ireland" is often used but the correct name for Ireland the nation-state is simply Ireland.
Secondly, the UK has a unique situation where both the constituent countries of the UK and the UK itself have the full status as a country. Politically they chose to be represented by the UK as a whole but it could be otherwise if the chose.
This being the case, the countries of the UK have in some cases chosen to be represented as the UK\GB and in others to represent themselves as they see fit.
Ireland is a separate country and represents itself politically and in sports.
In Ireland in many sports such as rugby, cricket and GAA, national federations had already been formed and these organisations continued to just keep doing as they were doing with the sports people from Northern Ireland and Ireland choosing to still be represented by these bodies.
In other sports like football, there were differing opinions and people from Ireland chose to start a new governing body. The Football Association of Ireland was formed to govern football in Ireland (country) and the Irish Football Association, which had governed the whole country (when it was only one country), became the body for Northern Ireland only.
The reasons why some sports went one way and some went the other is probably down to the demographics of the sport, but that's just opinion.
In the Olympics:
Since the first Olympics, the UK has chosen to be represented by one team. Now normally called "Team GB", the correct name would be "Team Great Britain and Northern Ireland", originally "Team Great Britain and Ireland". This is just for the Olympics and often countries represent themselves for competitions within individual sports.
Since gaining independence in 1922(but dominion status until 1937), Ireland has competed individually in the Olympics.
Since the Good Friday Agreement, citizens of Northern Ireland are entitled to citizenship of the UK, Ireland or both. They are thus entitled to represent either Team Ireland or Team GB in the Olympics. It would have been common before then though.
With the unusually complicated nationality statuses, agreements with international governing bodies have had to be sought although in the case of older sports it was effectively continuing the existing arrangement.
I'm sure I've left some holes, but there you go.