Basic Git commands

John John (304)
0

There are some fundamental git commands that you will use frequently that are hard to work into a "how-to" guide. Here are some basic git commands and how to use them. These are in no specific order.

git×1

Howchoo is reader-supported. As an Amazon Associate, we may earn a small affiliate commission at no cost to you when you buy through our links.

git branch -v will show you all of your local branches, their commit messages, and which branch is checked out.

git status will show you the status of the branch you currently have checked out. Before you switch branches, merge, pull or push you want to make sure you have a clean working directory and you can check with git status.

git checkout -b branch_name will create a branch from the branch you currently have checked out, and it will be called "branch_name" or whatever you'd like to call it.

git add . is a useful command that will version control any new files and remove from version control any files that you've deleted. If you have a file that has been added to git that you have deleted from your repository, it won't be deleted from git until you use git add ..

John John (304)
2 minutes

Sometimes we start writing code without managing our branches in advance. Then we make commits in master (or some other base branch) when we intended to carve off a new feature branch.