Shopify Theme Version Controlling Using GitHub
Tags: shopify, github, git, beginners
Published: 2023-10-27 14:24:22

Previously we learnt how to successfully [Set Up Your Local Environment For Shopify theme development](https://dev.to/quratulaiinn/setting-up-a-local-environment-for-shopify-theme-development-2ema).

Now Lets explore theme version controlling, an essential practice for seamless collaboration and efficient management of your Shopify store's themes. 

In this blog, we will discuss the step-by-step process of moving your development theme to GitHub and collaborating with your team members efficiently.

## Learning Outcomes

- Connect Shopify Development Theme With GitHub
- Create A Remote Repository On GitHub
- Link Your Local And Remote Repositories
- Push Your Changes To GitHub
- Create A Development Branch
- Merge Development Branch With Default Branch

## Lets Connect Shopify Development Theme With GitHub

Version controlling begins with setting up your local repository and linking it to GitHub. 

Using a good version control system helps you work together easily and makes sure you don't lose any old versions of your project. It also helps you add new things to your project without any problems. 

If you are not familiar with VCS you can read [this series](https://dev.to/hasabtech/git-basics-in-nutshell-248b) which explains everything in easiest possible way.

### 1. Initialize Your Local Repository

Here **local repository** basically refers to the project directory having our Shopify theme that we pulled from our store. 

Please follow the blog [here](https://dev.to/quratulaiinn/setting-up-a-local-environment-for-shopify-theme-development-2ema) if you haven't setup your environment yet. 

So the first step towards managing your project with Git is to initialize it. Follow these simplified steps:

**Step 1: Initialize Git In Your Project Directory**

Open your project directory in your preferred code editor and initialize Git by running the following command:

```bash
git init
```

This command initializes a new Git repository in your project folder, enabling Git to start tracking changes in your files.

![Git Bash Commands](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpcvzhi57v5c07y51g6q.png)

**Step 2: Add Your Files To The Staging Area**

To begin tracking changes in your files, you need to add them to the staging area. Run the command:

```bash
git add .
```

This command stages all the files in your project directory for the next commit. 

Ensure that you've added all the necessary files and directories before proceeding.

![Git Bash Commands](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/335g4z53cz7uvkpd3wks.png)

**Step 3: Make Your Initial Commit**

Once your files are staged, it's time to make your initial commit. Use the following command:

```bash
git commit -m "Initial Commit"
```

By executing this command, you create a snapshot of the current state of your project.

💡 Adding a meaningful commit message is crucial as it helps you and your team members understand the changes made in this particular commit.

![Git Bash Commands](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cruvais6zlh7inyi9lm2.png)

### 2. Create A Remote Repository on GitHub

To ensure that your local changes are saved on GitHub, follow these steps:

**Step 1: Create A New Repository**

1. Open GitHub and log in to your account.

2. Click on the '**+**' icon in the top right corner and select "**New repository**".

3. Choose an appropriate name for your repository in which you will push your development theme and configure other settings as needed.

4. Finally click on the "**Create repository**" button to generate your new remote repository on GitHub.

![GitHub Create Repository Page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8dukxzv03i3kzy23yjqs.png)

**Step 2: Link Local And Remote Repositories**

After creating the remote repository on GitHub, you need to connect it to your local repository.

**Command 1: Add Remote Repository URL**

```bash
git remote add origin your-repository-url
```

Replace **`your-repository-url`** with the URL of the remote repository you created on GitHub. 

This command establishes a connection between your local and remote repositories.

**Command 2: Push Your Changes To GitHub**

```bash
git push -u origin default-branch-name
```
Don't forget to replace `default-branch-name` with the actual name of your branch. In my case its `master`. 

![Git Bash Commands](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yj42vovg0snz8jo786jj.png)

This command sends the initial commit from your local repository to the remote repository on GitHub. 

The **`-u`** flag sets the upstream branch, enabling you to use **`git push`** for future pushes without specifying the remote repository's path or branch name.

**At this point if you will refresh your GitHub repository you will see all of your theme files are now available on GitHub.**

<aside>
💡 It's important to ensure that the local and remote branches have the same name to prevent any confusion during synchronization.

</aside>

## Implement A Development Branch Workflow

To ensure a seamless and error-free development process, it's highly recommended to adopt a development branch workflow.

 This approach helps making changes in a dedicated development branch before merging them into the default branch. 

<aside>
💡 An additional benefit of this workflow is when you want to integrate Shopify with your GitHub account, it allows you to maintain the development branch as your unpublished theme and continually apply changes to it, while the default branch remains as your live theme. Once you've tested the development branch changes on your online store, you can merge them with the main branch.

</aside>

Here are remaining steps to implement this workflow:

### 3. Create A Development Branch

Execute following command to create a new branch called `development`:

```bash
git checkout -b development
```

This command creates a new branch named "development" and switches to it, enabling you to work on new features and modifications without affecting the stable version.

![Git Bash Commands](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r7e9mvyw8ksdy3q09jn3.png)

### 4. Make Changes In Development Branch

In case you have made any changes in your development branch, lets say added a new feature, fixed a bug, or made any other modification, you can commit those changes by using the commands below:

```bash
git add .
git commit -m "Add feature XYZ"
```

![Git Bash Commands](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o8rubb67uwxj8f4q6pxv.png)

### 5. Merge Development Branch With Default Branch

Once the changes are thoroughly tested and verified, merge the development branch with the default branch which in my case is `master`.

```bash
git checkout default-branch-name
git merge development
```

![Git Bash Commands](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9yervnh56zhr4sngpdtp.png)

This process integrates the tested changes into the stable version, ensuring that your default branch always reflects the latest error-free version of your theme.

## Conclusion

In conclusion, integrating version control practices into your theme development process significantly enhances collaboration, minimizes errors, and facilitates efficient management of your Shopify themes. 

Take advantage of the tools and best practices outlined in this guide to elevate your theme development process within the comfort of your local environment as well to foster a productive and collaborative environment for your team members by making your theme available on GitHub.

For more Shopify tips and tricks, feel free to connect with me.

LinkedIn: [https://www.linkedin.com/in/quratulain](https://www.linkedin.com/in/quratulain-shoro-7792721a4/)

GitHub: [https://github.com/QuratAin](https://github.com/QuratAin)