---
# System prepended metadata

title: Git 101

---

# Git 101

To clone a repo ```git clone [repo url]```

To list local branches ```git branch -l```
To list remote branches ```git branch -r```

Create a branch: ```git branch feature```
To push a local branch to origin ```git push origin feature```

To delete a branch ```git branch -D feature```

Checkout/switch to a branch: ```git checkout feature```


# Git Rebase 

When you are in a situation like this ... 

![](https://i.imgur.com/VS4nxB8.png)

... you have two options:


The Merge Option - 

![](https://i.imgur.com/gEGGzNO.png)

```git merge feature master```


The Interactive Rebasing Option (Preferred @ Umbrage) - 

![](https://i.imgur.com/IdInspP.png)

Make sure the branch you are rebasing on is upto date
```
git checkout master
git pull
```

Switch over to your feature branch and initiate rebase
```
git checkout feature
git rebase -i master
```

This will open a text editor listing all of the commits that are about to be moved:

```
pick 33d5b7a Message for commit #1
pick 9480b3d Message for commit #2
pick 5c67e61 Message for commit #3
```

Go in and squash all your commits by changing to: 

```
pick 33d5b7a Message for commit #1
squash 9480b3d Message for commit #2
squash 5c67e61 Message for commit #3
```

Save the file and continue the rebase

```
git rebase --continue
```

Once you are finished with the rebase process check that the rebase was successful before force pushing to origin: 

```
git push -f
```

# Git Rebasing with Conflicts



For more in depth info checkout https://www.atlassian.com/git/tutorials/merging-vs-rebasing