Git with it!: A Starter Version of Handy Dandy Cheatsheet of Git Commands

I have to admit that there are times when I brain fart and forget a Git command. Then I blankly stare at the screen and watch the keystroke in hopes that I would remember it…or I’ll just consult Google for the command. You would think that after this has happened several times, I would have a handy dandy cheatsheet for all the git commands that I most commonly use….well I don’t. So, here is my cheatsheet for those of you who are just starting to use Github.

Sharing is caring!

For starters:

$ git init project_name
Initializes a new git repo with your project in your directory: /Users/username/project_name/.git/

$ git clone
Clones an existing repo onto your own github/into your own directory

Now let’s get started:

$ git branch feature_you_are_working_on
Branches you off from the master branch to separate the code you are working on from your existing code. This keeps the code that has already been pushed up clean.

$ git branch
Allows you to check your current branch

$ git checkout branch_name
If you are not on the branch that you want to be, this command switches you to the existing branch that you want to work on. At the same time, this updates your directory.

$ git status
Allows you to check the current status of your project and the state of all your files in your project.

For your work:

$ git add .
Pushes up all the tracked files of your project at it’s last saved state to Github.

$ git commit -m “message”
Attaches your files that you just pushed up to your own personalized message. This message usually details what you did or change/update.

OR you can combine the two commands into one with,

$ git commit -am “message”

$ git push
For the last stage of committing all of the working files of your project. A commit records all of your changes, your name for being responsible for these changes, the message that you write for your commit and a commit id for tracking. This pushes all of your working files from your local repo to the remote repo (Github).

$ git pull
If your local repo is out of date with your remote repo, this may cause some conflicts. This pulls the remote repo’s last committed files to your own local repo so you can have the most updated code.

I hope these couple of git commands are useful. They’re meant for you to get started and comfortable with using Github.

Happy coding! ✌️

Like what you read? Give Jenny Lai a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.