7 Basic Git Commands That Developers Should Know

Daniela S. Alzate
3 min readJun 9, 2021

Git is an open source DVC (Distributed Version Control System) that integrates all the changes from multiple and simultaneous work, keeping all the development history centralized.

Git is widely used in the software industry for this reason it is a highly requested skill for developers. In this post we will know some basic commands to know how to work with Git.

Note: To understand this article, you need to know the basics concepts of Git, for more infomation read my previous post

1. git clone

Git clone is a command for downloading existing files or code from a Server Repository, creating an identical copy of the latest version of the server repository and saves it to your local repository.

git clone <Server-Repository> <Folder-Name(Optional)>

For example:

git clone example

You can also specify the name of the folder in which you will create the local repository.

git clone folder name parameter

2. git init

Git init is a command for initialize an empty local repository. This command is very usefull when you want to start a new project. Once the command is executed, it will create a .git folder where all the repository information will be stored.

git init <Repository-Name>

For example:

git init command

3. git branch

Git branch is a command to keep work in parallel on the same project. Git branch is used for creating, listing or deleting branches. Usually, a branch is created to work on a new feature. Once the feature is completed, it is merged back to the main branch and we delete the branch.

# For creating a new branch
git branch <Branch-Name>
# For deleting a branch
git branch -d <Branch-Name>
#For listing branches.
git branch --all

4. git checkout

Git checkout is a command mostly used to switch between branches but it can be also use for checking out files and commits.

# For switching to another branch
git checkout <Branch-Name>
# For checking out commits
git checkout <Commit-Id>
#For creating new branch and switching it
git checkout -b <Branch-Name>

5. git commit

Git commit is a command to save our changes or checkpoint functionality only for the local repository. Using git checkout you can go back to later if you needed. It is mandatory to write a short message to explain what we have developed or changed. Before doing a git commit it is recommended to perform a git add.

git add .
git commit -m <Short-Message>

6. git push

Git push is used after a git commit command, at the moment that is required to send the local commits to the server repository. Git push ONLY send changes or functionalities that are committed.

git push -u origin <Branch-Name>

7. git pull

Git pull command is used to get and applies the lastest commits from the server repository to the local repository.

git pull origin <Branch-Name>

--

--