# Creating and Switching Between Branches

### Creating a Branch

To create a new branch in Git, you can use the `git branch` command followed by the desired branch name. Let's say we want to create a branch named `feature-branch`:

```bash
git branch feature-branch
```

This command creates the branch but does not switch to it yet. You can list all branches in your repository using `git branch` without any arguments:

```bash
git branch
```

output:

```
* main
  feature-branch
```

The asterisk (\*) indicates the currently active branch, which is `main` in this case.

We can also create a branch using the checkout command:

```bash
git checkout -b feature-branch
```

This command would create and checkout the newly created branch.

***

### Switching Between Branches

To switch to a different branch, you can use the `git checkout` command followed by the branch name. For example, to switch to the `feature-branch` we created earlier:

```bash
git checkout feature-branch
```

The output should indicate that you have switched to the `feature-branch`.

`Switched to branch 'feature-branch'`

Now you are in the `feature-branch` and any changes you make and commit will be isolated within this branch. You can verify your current branch by running `git branch`:

```bash
git branch
```

output:

```
  main
* feature-branch
```

The asterisk (\*) has moved to indicate that you are now on the `feature-branch`.

{% hint style="success" %}
creating and switching between branches is a powerful feature of Git that enables effective collaboration and parallel development. By following best practices for branch naming and management, you can maintain a well-organised and efficient workflow.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitdeveloperguide.solomonmarvel.com/working-with-git/creating-and-switching-between-branches.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
