Basic git commands you will ever need
Published: 2020-06-26 07:22:27

---
title: Basic git commands you will ever need
published: true
tags: 
canonical_url: https://www.vickylance.com/2019-07-26-basic-git-commands-you-will-ever-need/
---

## <svg enable-background="new 0 0 32 32" version="1.1" viewbox="0 0 32 32" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="m28 0h-16c-4.418 0-8 3.582-8 8s3.582 8 8 8v16h4v-28h4v28h4v-28h4v-4z" fill="#b24b31"></path></svg>To initialize a git repo

To init a git project

```shell
cd <path to root folder of project>
git init
```

## <svg enable-background="new 0 0 32 32" version="1.1" viewbox="0 0 32 32" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="m28 0h-16c-4.418 0-8 3.582-8 8s3.582 8 8 8v16h4v-28h4v28h4v-28h4v-4z" fill="#b24b31"></path></svg>To check the status of changed files

To check the status of files for changes

```shell
git status
```

## <svg enable-background="new 0 0 32 32" version="1.1" viewbox="0 0 32 32" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="m28 0h-16c-4.418 0-8 3.582-8 8s3.582 8 8 8v16h4v-28h4v28h4v-28h4v-4z" fill="#b24b31"></path></svg>To add file for commit

To add all changed files

```shell
git add -A
```

To add all changes in current directory

```shell
git add .
```

To add specific files

```shell
git add <file path>
```

To add multiple files

```shell
git add <file1 path> <file2 path>
```

## <svg enable-background="new 0 0 32 32" version="1.1" viewbox="0 0 32 32" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="m28 0h-16c-4.418 0-8 3.582-8 8s3.582 8 8 8v16h4v-28h4v28h4v-28h4v-4z" fill="#b24b31"></path></svg>To commit files to git

To make a commit with a commit messae

```shell
git commit -m "commit message"
```

## <svg enable-background="new 0 0 32 32" version="1.1" viewbox="0 0 32 32" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="m28 0h-16c-4.418 0-8 3.582-8 8s3.582 8 8 8v16h4v-28h4v28h4v-28h4v-4z" fill="#b24b31"></path></svg>Managing remote repos

Adding a remote URL

```shell
git remote add origin <repo URL>
```

To add multiple remote URL

```shell
git remote add <any key for remote URL> <repo URL>
```

To push code to remote repo

```shell
git push
```

To pull code from remote repo

```shell
git pull
```

## <svg enable-background="new 0 0 32 32" version="1.1" viewbox="0 0 32 32" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="m28 0h-16c-4.418 0-8 3.582-8 8s3.582 8 8 8v16h4v-28h4v28h4v-28h4v-4z" fill="#b24b31"></path></svg>Manipulating git branches

To create a new branch using current branch as base

```shell
git checkout -b <new branch name>
```

To checkout to existing branch

```shell
git checkout <branch name>
```

To push the new branch to remote repo

```shell
git push -u <remote key> <branch name>
```

To merge a branch’s code to current branch

```shell
git checkout <current branch>
git merge <other branch>
```

## <svg enable-background="new 0 0 32 32" version="1.1" viewbox="0 0 32 32" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="m28 0h-16c-4.418 0-8 3.582-8 8s3.582 8 8 8v16h4v-28h4v28h4v-28h4v-4z" fill="#b24b31"></path></svg>Stashing

To stash a code without commit

```shell
git stash
```

To pull a stashed code

```shell
git stash pop
```