Open up Quicktime, and select New Screen Recording in the File menu.
Click the big red button.
Select the area of the screen you wish to record.
Go and do whatever it is you want to record.
Then when you are done, click on the stop button in the menu bar.
It will open up a quicktime video with your screen capture.
Be sure to cleanup the video by trimming the beginning and end.
Don't make the recording any longer than it needs to be.
For converting the video to a gif, I use an app called GIFBrewery. Although it now costs about $4-5.
You can also use apps like Photoshop, or even online services to convert your video to GIF.
Open up the video in GIF Brewery and click the "Create GIF" button.
Save your file.
Then drag and drop the GIF onto any github textarea where markdown is supported.
Seems good, but there is simpler way to complete this task with Capture Gif made by me.
http://www.pixelegg.me/capture-gif