Cutting hair on the head is an obligatory ritual of Hajj:
ولا تحلقوا رءوسكم حتى يبلغ الهدي محله
And do not shave your heads until the sacrificial animal has
reached its place of slaughter.
— Quran 2:196
لتدخلن المسجد الحرام ان شاء الله امنين محلقين رءوسكم ومقصرين
لا تخافون
You will surely enter al-Masjid al-Haram, if Allah wills, in safety,
with your heads shaved and [hair] shortened, not fearing
[anyone].
— Quran 48:27
قال لما قدم النبي صلى الله عليه وسلم مكة امر اصحابه ان يطوفوا بالبيت،
وبالصفا والمروة، ثم يحلوا، ويحلقوا او يقصروا
Narrated Ibn `Abbas:
When the Prophet (ﷺ) came to Mecca, he ordered his Companions to
perform Tawaf round the Ka`ba and between Safa and Marwa, to finish
their Ihram and get their hair shaved off or cut short.
— Sahih Bukhari, Book of Hajj
For men, shaving it completely is the Sunnah and the preferable thing to do, though trimming it short is also permissible.
قال حلق النبي صلى الله عليه وسلم وطايفة من اصحابه، وقصر بعضهم
The Prophet (ﷺ) and some of his companions got their heads shaved
and some others got their hair cut short.
— Sahih Bukhari, Book of
Hajj
ان رسول الله صلى الله عليه وسلم قال " اللهم ارحم المحلقين
". قالوا والمقصرين يا رسول الله قال " اللهم ارحم المحلقين ".
قالوا والمقصرين يا رسول الله قال " والمقصرين ". وقال الليث
حدثني نافع " رحم الله المحلقين " مرة او مرتين. قال وقال عبيد
الله حدثني نافع وقال في الرابعة " والمقصرين
Narrated Abdullah bin `Umar:
Allah's Messenger (ﷺ) said, "O Allah! Be merciful to those who have
their head shaved."
The people said, "O Allah's Messenger (ﷺ)! And (invoke Allah for)
those who get their hair cut short."
The Prophet (ﷺ) said, "O Allah! Be merciful to those who have their
head shaved."
The people said, "O Allah's Messenger (ﷺ)! And those who get their
hair cut short."
The Prophet (ﷺ) said (the third time), "And to those who get their
hair cut short."
Nafi said that the Prophet (ﷺ) had said once or twice, "O Allah! Be
merciful to those who get their head shaved," and on the fourth time
he added, "And to those who have their hair cut short."
— Sahih Bukhari, Book of Hajj
If you decide to only trim the hair, then it should be shortened at minimum by the length of your fingertip.
Cutting hair is required, be it the first Hajj or a repeated one. There is a view that shaving (rather than trimming) is obligatory on the first Hajj but this isn't mainstream.
From Mughni:
إلا أنه يروى عن الحسن ، أنه كان يوجب الحلق في أول حجة حجها . ولا يصح
هذا ; لأن الله تعالى قال : محلقين رءوسكم ومقصرين
[My own translation so take care]
... the exception narrated from Hassan (Basri?) that it is wajib to shave the head on the
first hajj. However this is not correct since Allah said:
heads shaved and hair shortened 48:27
From Tafsir Qurtubi:
وأجمع أهل العلم على أن التقصير يجزئ عن الرجال ، إلا شيء ذكر عن الحسن
أنه كان يوجب الحلق في أول حجة يحجها الإنسان
[My own translation so take care]
It is the consensus of the people of knowledge that trimming hair is
permissible for men, except for what was mentioned from Hassan who
said that in the first Hajj that a person performs, it is obligatory
to shave the head.