Must Know Git Commands For Developers

Steven Wu
6 min readMay 23, 2021

A simple guide to Git commands.

Photo by Fotis Fotopoulos on Unsplash

Intro

I remember on my first day of learning Software development, I had to clone a repo with a lesson from my instructor at The Flatiron School and and I had no clue what she was talking about. A year later, Git seems so easy and second nature to me as a developer that I’m shocked at how little I knew about Git at the time.

Today I will show you how to use Git with GitHub and share some of my must know Git commands.

What is Git?

Git is the most popular version control system in the world. It records the changes to your code and store it in something called a repository(repo). It’s also great to track the code history and work together with fellow developers since repos can be be shared with other developers.
Git is a distributed control system, this means that you can have copies of your code on multiple user’s computers so if the main version shuts down we can spin it up from another user with ease.
I’m constantly switching between my macbook and my gaming pc, so my favorite part about Git is having my code easily available from any of my computers through Github.

Install Git:

1a. Download the Latest version of Git for MacOS
1b. Download the Latest version of Git for Windows
1c. Download the Latest version of Git for Linux

2. Setting your username in Git

3. Setting your commit email address in Git

Git init

Once you have installed Git, you can use the git init command in any directory/folder you want to set that folder as a Git repo.

git init

Git add

You can use the git add command to add any specific files you want to keep track of in your Github repo.

You can simply use git add . to add all files to your repo.

git add .

Git Status

the git status command is used to check the status of your repo on your local machine.

Since I’ve added all the files, the terminal is telling me all my files are staged and ready to be committed to the repo.

git status

Git Commit

The git commit command is used to commit/save any changes from your local machine to your repo on Github.

You have to use the -m flag with the git commit command to set the commit message for logging purposes.

git commit -m "message"

Git branch

This is used to create a branch or a version so to speak of your repo. Since we haven’t created any branch yet I’m calling the -m flag to specify this as the master branch.

git branch

Git remote

The git remote command is use for controlling the GitHub remotes. To create a new remote, you can go to GitHub’s UI and just start a new repo and they will provide you with a new shiny remote key.

Since there aren’t any remotes associated to my local repo yet, I used the add origin flag which specifies that this key will be the origin key to the repo.

git remote

Git push

Once everything is added and committed in your repo, you call the git push command to push your changes to the GitHub repo

git push

Git checkout

Git checkout is used to switch to another branch on your local machine.

I’ve created a new branch and I’ve used the checkout command to move in that branch

git checkout

Git merge

Git merge is for merging branches, so in my example I’ve changed the app in the new-branch and I call git merge to merge the new-branch with the main branch

git merge

Git log

The git log command is to see your log of the commits and get their IDs if you need it.

git log

Git reset

If for any reason you’re unhappy with your code, you can simply call git reset with the commit ID to reset it back to that commit stage.

git reset

Git Clone

This command is used to make a copy of your repo down to your local machine. You use this command by calling git clone and entering the remote key and this will create a new folder in your current directory with all the files from your repo.

git clone

Git pull

This command is used to update your repos from your local machine. For example if you and I were working on the same repo and I’ve made some changes while you were away, you simple call git pull and your local repo will be updated with whatever changes to the repo I have committed and pushed up to Github.

git pull
Photo by Roman Synkevych on Unsplash

Conclusion

Git is one of the most powerful tools for developers in or out of the professional environment. This is definitely one of the first things you should learn as a developer even before you learn how to code, since you can store all your work in Git, you can go back and see your code as well.

You should definitely read the documentation to Git since this is such a powerful tool but I hope this little guide will be enough to get you started.
This is a pretty good cheatsheet if you need as well.

Thank you for reading and please subscribe and smash that like button to make it clap or leave any comments where I can make improvements!

--

--