The Ops Community ⚙️

Cover image for Basic Git Commands to get started - 14 days of Git
Sarah Lean
Sarah Lean

Posted on • Originally published at

Basic Git Commands to get started - 14 days of Git

So far on my 14 days of Git learning journey I have dug into:

Now it's time to start using Git and get familiar with some of the basic commands.

Git clone

Git clone is the command that will help you download an existing remote repository (like GitHub for example) to your machine.
For example if you head over to any GitHub repository and click on the green Code button. It will display a URL. Take a copy of that URL.

GitHub Repo screenshot

Open up your command line tool and type in:

git clone
Enter fullscreen mode Exit fullscreen mode

And Git will take a copy, or clone the entire project from the remote source to your machine.

Git clone in action

Git add

When we work on a local copy of a repository we will be creating, modifying, or delete files. When we do that we need to add those changes to our next commit so they are copied to the remote repository.

Git add starts to prepare our changes ready to be saved and sent to the remote repository.

We can add a single file with the command:

git add filename
Enter fullscreen mode Exit fullscreen mode

Or we can add all the files and changes we made with the command:

git add -A
Enter fullscreen mode Exit fullscreen mode

Your changes are now ready to be committed.

Git commit

There comes a point when you are working on your local repository that you want to save your changes.

Git commit is like setting a checkpoint. You can come back to this checkpoint at a later point if you need to.

When we issue the git commit command we need to issue a message to explain the changes we have made. This will help you or the next person along understand what has changed.

An example of using git commit can be seen below:

git commit -m "I have made changes to the code to add a new feature"
Enter fullscreen mode Exit fullscreen mode

Git commit command

Git push

Once we have committed our changes we need to send them to the remote repository. We can do this using the push command.

The git push command uploads the commits you have made to the remote repository. Only committed changes will be uploaded.

There are several ways to use the git push command, the most common will be:

git push
Enter fullscreen mode Exit fullscreen mode

Git push command

Git pull

Git pull is the command you would use to get any updates from the remote repository.

This command actually does two things in the background. It is a combination of two other commands, git fetch and git merge.

git pull
Enter fullscreen mode Exit fullscreen mode

_There are times when you will use this command it will throw up errors or conflicts that you need to resolve but it will pull down any changes for you. _

Git init

Git init is a great command to be aware of it. IT can convert an existing project or folder into a Git repository.

Most git commands are not available until a repository is initialised, so typically this is the first command you will run when starting a new project on your local machine.

When you use git init it create a .git subdirectory in the working directory. This contains all the necessary Git metadata for the new repository.

You can use git init in a couple of way.

If you have an existing folder structure with files and code within it that you want to turn it into a git repository you can issue the command:

git init
Enter fullscreen mode Exit fullscreen mode

Git init command

If you haven't created a folder or started creating any code you can issue the following command to create the folder and initialise it as a git repository:

```git init NewProject

## 14 days of Git
These are some of the basic Git commands that you should know.  They really are the basics for getting involved with Git. 

The next step of 14 days of Git is to dig deeper into the commands that we can use with Git and why we need to know them.  Be sure to subscribe and join us for that step in the learning journey!

You can follow along here: [](
Enter fullscreen mode Exit fullscreen mode

Top comments (0)