Git Branches in Five Minutes or Less
Tags: git, branches, intro, short
Published: 2020-04-06 21:50:07

---
title: Git Branches in Five Minutes or Less
published: true
description: Concise summary of Git Branches
tags: git, branches, intro, short
series: Git bit-by-bit
---
# This Series
Git bit-by-bit is a tutorial series covering the Source Control Management software Git. In the last post I covered everything you need to start using Git as-soon-as-possible. Today we're going to cover how to manage multiple sets of changes.

# Vocabulary
1. Repository <a name="repository"></a>
  * Location where changes are tracked.
3. Commit <a name="commit"></a>
  * A set of changes to be recorded.
2. Branch <a name="branch"></a>
  * A collection of commits.
5. Tag <a name="tag"></a>
  * A string assigned by the user to identify a commit.
6. Merge <a name="merge"></a>
  * Combine the commits of one branch, into another.
7. Conflict <a name="conflict"></a>
  * A file with two sets of changes, that are not in agreement.

# Commands
For this section, you should have an empty repository with a single commit on the master branch. If you don't, please follow the commands [in the last entry](https://dev.to/fastflowz/git-essentials-in-five-minutes-or-less-2486)
```shell
user:~/project/tutorial$ git branch
```
* Lists all of the local branches that are being tracked.
```shell
user:~/project/tutorial$ git checkout -b <branch>
```
* Create a new branch with the name [\<branch\>](#branch).
```shell
user:~/project/tutorial$ git checkout <branch>
```
* Switch to [\<branch\>](#branch).
```shell
user:~/project/tutorial$ git tag "v0.0.1"
```
* Assigns a [tag](#tag) of "v0.0.1" to the last commit.
```shell
user:~/project/tutorial$ git checkout tags/<tag>
```
* Switch to the commit that was assigned [\<tag\>](#tag)
```shell
user:~/project/tutorial$ git merge <branch> --no-commit --no-ff
```
* Git will prepare to join the history of [\<branch\>](#branch) with the current [branch](#branch). It will not [commit](#commit) it right away, allowing you to compare the incoming changes.
```shell
user:~/project/tutorial$ git merge <branch>
```
* Git will attempt to join the changes you created in [\<branch\>](#branch), with the state of the current [branch](#branch). 
* If successful, it will automatically make a new [commit](#commit) containing [\<branch\>'s](#branch) changes.
* If Git cannot join the changes together, it will result in a [merge](#merge) [conflict](#conflict). This can fixed, by deciding which sets of changes you would like to have committed. The current [branch](#branch), or \<branch\>.

# More Information:
This entry covered the basics of maintaining multiple sets of changes within a git repository. How to create new branches, how to switch between branches, how to leave a friendly trial behind and how to combine different sets of changes. My number one tip with this would be, to not fear merge conflicts. It can be startling and/or worrying to have to pick between two sets of changes. But if you merge often, take your time resolving them, and verify that the fixes don't break existing code. You'll master it in no time.

---
Find me on [Twitter](https://twitter.com/FastFlowZ) | [LinkedIn](https://www.linkedin.com/in/dakota-lewallen/)
Sponsor me on [Github](https://github.com/iamflowz)
Like the article? [Buy me a coffee!](https://www.buymeacoffee.com/iamflowz)