Using Git in the IT Ops World (Not Just for Developers)
Using Git in the IT Ops World (Not Just for Developers)
When you hear "Git," if you have heard it before, your mind might immediately jump to software development. Git is a version control system beloved by developers, but its usefulness extends beyond coding. If you're in IT Operations (IT Ops), Git can still be a powerful tool to manage scripts, configuration files, and even documentation. Let’s explore how Git can simplify your workflow, even if you’re not writing software.
Why Use Git in IT Operations?
In IT Ops, it's common to work on scripts and configuration files that impact critical infrastructure. These files evolve over time, and having a way to track changes is essential. Git helps you:
Track versions: You can track every modification made to a file, making it easy to see what changed and why.
Recover from mistakes: Accidentally overwrite a file? Git allows you to roll back to a previous version.
Git uses a client-server model, where your local machine acts as the client and a remote Git server (like GitHub, GitLab, or a self-hosted server) acts as the server. The local client is where you store, modify, and track files using Git. When you're ready to back up your changes or collaborate with others, you can push your commits to the remote server, which acts as a centralised place to store and share code.
This test lab project depends on numerous scripts and configuration files, so having Git as the foundation will be incredibly useful for tracking changes, managing versions, and maintaining an organised workflow. It will ensure that everything is properly documented and easily reversible, setting you up for success in the steps that follow.
How the Client-Server Model Works:
Client (Your Local Machine):
- You make changes, track versions, and commit updates to your local repository.
- Everything is saved locally, and Git doesn't require an internet connection for these operations.
- you will need to install Git on your windows machine
Server (Remote Git Repository):
- This is where you push your code when you're ready to share it or back it up.
- The server allows collaboration, enabling others to pull your changes or contribute their own.
Why You Don't Need a Server for a Test Lab Project
For a personal lab project, you don’t need a remote server. Git works perfectly fine as a standalone version control tool on your local machine. You can initialise a repository, track your changes, commit updates, and roll back if needed—all without setting up or using a server. This is ideal for quick experiments or projects where collaboration isn’t needed.
Adding a Server for Collaboration
If you want to practice collaboration or work with another person on your lab project, adding a remote Git server is beneficial. By setting up a Git server (such as using GitHub or GitLab), you and another collaborator can:
- Push your changes to a shared repository.
- Pull the latest changes made by others.
- Review each other's work, merge changes, and resolve any conflicts.
This setup mimics real-world collaboration, making it great practice for team-based projects.
Simple Git Workflow
for IT Ops
You don’t need a complicated branching model. In fact, for IT Ops, simplicity is key. Here’s an easy workflow to get started:
- Initialise a Repository
Once you’ve created your script or configuration file, initialise a Git repository:
git init
This sets up a new repository in your working directory.
- Add Your Files
Add your scripts or config files to the repository:
git add .
This stages all changes for commit.
- Commit Your Changes
After staging, commit your changes:
git commit -m "Initial commit of configuration script"
Always write meaningful commit messages so you know what changes were made.
- Push to a Remote Repository
although as mentioned above its not needed to work, It's a good practice to push your changes to a remote repository which ensures you have a backup and can easily share your work if you wanted to
Some great options for free private Git repositories include GitHub, GitLab, Bitbucket, SourceHut, Gitea (self-hosted), AWS CodeCommit, Azure Repos, and Keybase. GitHub, GitLab, and Bitbucket are popular cloud-hosted solutions offering free private repositories with useful integrations. SourceHut and Gitea are lightweight, with Gitea requiring self-hosting for full control. AWS CodeCommit and Azure Repos integrate seamlessly with their cloud platforms, while Keybase provides secure, encrypted Git repositories for small projects.It's a good practice to push your the setup of each is slightly different but will provide you with a URL to publish to
git remote add origin <remote-repo-url>
git push -u origin master
Collapsing Commits Before Pushing
If you’ve made several small commits (e.g., fixing typos or adjusting paths), you might want to clean them up before pushing to your remoterepository. This can help keep the history clean and easy to understand.
To collapse commits, use git rebase:
git rebase -i
HEAD~n
Where n
is the number of recent commits you want to combine.
When you perform a Git rebase, Git will open an editor to give you the option to squash commits. Squashing allows you to combine multiple commits into a single, cohesive commit, which helps to maintain a cleaner and more readable project history. Here’s how you can squash commits:
Start the Rebase Process:
git rebase -i HEAD~n
Replace
n
with the number of commits you want to look back. For example:git rebase -i HEAD~3
Open the Editor: Git will open an editor with a list of commits. The list will look something like this:
pick e3a1b2c Commit message 1 pick f4d5e6f Commit message 2 pick a7b8c9d Commit message 3
Choose Commits to Squash: Change
pick
tosquash
(ors
) for the commits you want to combine into the previous commit. For example, to squash the last two commits into the first:pick e3a1b2c Commit message 1 squash f4d5e6f Commit message 2 squash a7b8c9d Commit message 3
Save and Close the Editor: Save your changes and close the editor. Git will then combine the commits and open a new editor to let you adjust the commit message.
Edit the Commit Message: In the new editor, you will see the commit messages combined. You can edit the commit message for the combined commit. It might look something like this:
# This is a combination of 3 commits. # The first commit's message is: Commit message 1 # This is the commit message for the second commit: Commit message 2 # This is the commit message for the third commit: Commit message 3
Edit this to reflect the combined changes as you see fit.
Complete the Rebase: Save and close the editor once you’re satisfied with the commit message. Git will complete the rebase process and update the commit history.
Squashing commits helps keep your project history neat and easy to understand, making it simpler to track changes and maintain a clean log.
Keep It Simple
Branching is an essential part of Git for developers, but in IT Ops, you might not need to branch often. If you’re working on your own or with a small team, working directly in the master
branch and keeping your commit history tidy might be enough.
However, for larger changes or testing, consider creating a branch:
git
checkout -b new-feature
Once you're happy with the changes, merge it back into the master
branch:
git
checkout master
git merge new-feature
Conclusion
Git might seem like a developer tool, but it’s a fantastic asset for IT Ops too. It allows you to version scripts, collaborate with teammates, and roll back changes easily. By keeping the process simple and focusing on tracking, committing, and occasionally collapsing commits, you can harness the power of Git without overwhelming yourself.
Incorporating Git into your IT Ops workflow can make a world of difference, ensuring that your critical files are always safe, organised, and up to date!
In the next post, I’ll guide you through the process of installing Git on your machine and setting up a remote repository. Whether you’re new to version control or looking to streamline your workflow, I’ll work through the essentials of getting git up and running
Comments
Post a Comment