This evening, I decided that I'd like to start utilizing source control on some of my projects. I figure that this will have the additional benefit of letting y'all easily view some of my projects and emulate them in your own labs, since I'll be using public repos on Github.
This example will be covering my the setup for a repo to house my docker compose files, specifically.
While the process was simple, I wanted to do a quick write up covering how I went about doing this.
Creating a Repo
To start, I created a repository for all of my docker-compose files to live in. Github makes this process very easy and lets you do a bit of basic configuration, like adding a repo name and description.
Creating a .gitignore file
Once my repo was created, I went into my
docker directory, which houses many subdirectories, each of which are related to a specific container and house a docker-compose.yml file.
In that "root" docker directory, I created file called
.gitignore, which tells git what files/directories to ignore when syncing with Github.
For my purposes, I did not want all of my config, data, device, etc directories to all be synced to a public repository. Because of this, I added these few lines into my
.gitignore file to exclude them from being pushed up to Github:
**/data **/devices **/config
Pushing to Github
Now the easy part: pushing to our newly created git repository. To do this, we'll run the following commands:
git init git remote add origin https://github.com/your_user/your-repo-name.git git branch -M main git push -u origin main
And with that, your code will be pushed to your new repository!
In the future, if I make changes to any of these files and want to push the changes to Github, I will run the following commands:
git add . git commit -m "insert message here" git push
Should you want to check out the docker-compose repo that I referenced in this post, you can find it here.