At the beginning of the novel the reader learns about the world of Hobbiton and its inhabitants.
Samwise Gamgee is the character in "The Lord of the Rings" whose faith, devotion and loyalty impresses in the story. And his quote: "Don't you lose him, Samwise Gamgee. And I do not mean to, I do not mean to." (And "Don't you leave him, Samwise Gamgee...)
In the film there is an impression that it was Gandalf who told him so: though Gandalf let Sam be Frodo's companion in the book it was the elf called Gildor...
Going back to Samwise Gamgee: the end of chapter 2: a moving and yet funny episode showing how deeply the friends were attached to each other.
"
Suddenly he stopped as if listening. Frodo became aware that all was very quiet, inside and outside. Gandalf crept to one side of the window. Then with a dart he sprang to the sill, and thrust a long arm out and downwards. There was a squawk, and up came Sam Gamgee’s curly head hauled by one ear.
‘Well, well, bless my beard!’ said Gandalf. ‘Sam Gamgee is it? Now what may you be doing?’
‘Lor bless you, Mr. Gandalf, sir!’ said Sam. ‘Nothing! Leastways I was just trimming the grass-border under the window, if you follow me.’ He picked up his shears and exhibited them as evidence.
‘I don’t,’ said Gandalf grimly. It is some time since I last heard the sound of your shears. How long have you been eavesdropping?’
‘Eavesdropping, sir? I don’t follow you, begging your pardon. There ain’t no eaves at Bag End, and that’s a fact.’
‘Don’t be a fool! What have you heard, and why did you listen?’ Gandalf’s eyes flashed and his brows stuck out like bristles.
‘Mr. Frodo, sir!’ cried Sam quaking. ‘Don’t let him hurt me, sir! Don’t let him turn me into anything unnatural! My old dad would take on so. I meant no harm, on my honour, sir!’
‘He won’t hurt you,’ said Frodo, hardly able to keep from laughing, although he was himself startled and rather puzzled. ‘He knows, as well as I do, that you mean no harm. But just you up and answer his questions straight away!’
‘Well, sir,’ said Sam dithering a little. ‘I heard a deal that I didn’t rightly understand, about an enemy, and rings, and Mr. Bilbo, sir, and dragons, and a fiery mountain, and - and Elves, sir. I listened because I couldn’t help myself, if you know what I mean. Lor bless me, sir, but I do love tales of that sort. And I believe them too, whatever Ted may say. Elves, sir! I would dearly love to see them. Couldn’t you take me to see Elves, sir, when you go?’
Suddenly Gandalf laughed. ‘Come inside!’ he shouted, and putting out both his arms he lifted the astonished Sam, shears, grass-clippings and all, right through the window and stood him on the floor. ‘Take you to see Elves, eh?’ he said, eyeing Sam closely, but with a smile flickering on his face. ‘So you heard that Mr. Frodo is going away?’
‘I did, sir. And that’s why I choked: which you heard seemingly. I tried not to, sir, but it burst out of me: I was so upset.’
‘It can’t be helped, Sam,’ said Frodo sadly. He had suddenly realized that flying from the Shire would mean more painful partings than merely saying farewell to the familiar comforts of Bag End. ‘I shall have to go. But’ - and here he looked hard at Sam - ‘if you really care about me, you will keep that dead secret. See? If you don’t, if you even breathe a word of what you’ve heard here, then I hope Gandalf will turn you into a spotted toad and fill the garden full of grass-snakes.’
Sam fell on his knees, trembling. ‘Get up, Sam!’ said Gandalf. I have thought of something better than that. Something to shut your mouth, and punish you properly for listening. You shall go away with Mr. Frodo!’
‘Me, sir!’ cried Sam, springing up like a dog invited for a walk. ‘Me go and see Elves and all! Hooray!’ he shouted, and then burst into tears."
By the way, Sam's favourite (often used) words seem to be "if you follow me", "if you know what I mean" and the like.
The book is so much about friendship.
"The Lord of the Rings" is also interesting as it shows relationships between people of different backgrounds and social status but these distinctions kind of disappear: Frodo is Sam's master, Sam is his gardener, which do not stop them from being friends actually, the same is for Frodo and Aragorn (a simple hobbit and a patronising well-bred leader (king)), Gimly and Legolas. As for Frodo and Sam -- it is a continuation of the servant-master-friendship theme in literature, which is found, for example, in the "Puss in Boots" tale, Beaumarchais' "The Marriage of Figaro", P.G. Wodehouse's "Jeves and Wooster"stories.
As it is told in Carpenter's biography of J.R.R Tolkien (if I remember rightly), the image of Samwise was partly drawn from or inpired by his orderly during World War I (in which the writer did not happen to fight because he had fallen ill). There is also a lot of curious information. Tolkien himself valued friends, there was the Inkling club.
"The Lord of the Rings" book can be read online here
http://www.ae-lib.org.ua/texts-c/tolkien__the_lord_of_the_rings_1__en.htm (including the author's foreword).