Basic Git Commands to get started - 14 days of Git
Tags: 14daysofgit, git, devops
Published: 2022-09-20 13:02:27

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

- [What is version control?](https://www.techielass.com/what-is-version-control)
- [What is Git?](https://www.techielass.com/what-is-git)
- [Installing Git](https://www.techielass.com/installing-git/)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nr06eg21gm5wxzpr0ert.png)

Open up your command line tool and type in: 
```bash
git clone https://repository-url.link
```

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

![Git clone in action](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/msd5juvpuibn7nzqvaic.png)

## 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: 

```bash
git add filename
```

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

```bash
git add -A
```
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: 
```bash
git commit -m "I have made changes to the code to add a new feature"
```

![Git commit command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2w3qkkv0fv61oxjp7vbe.png)

## 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: 

```bash
git push
```

![Git push command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uds0miwuyr888zzcev3u.png)

## 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. 

```bash
git pull
```

_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: 

```bash
git init
```

![Git init command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xqswass1hm1wlvtuamj5.png)

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: [https://github.com/weeyin83/14daysofgit](https://github.com/weeyin83/14daysofgit)