Tracing Our Steps: A Guide to Git (Part 6)

Practical (Git) Magic

<a href="https://www.vecteezy.com/free-vector/command">Command Vectors by Vecteezy</a>

This is a series of posts about using Git. You can read the previous entries at:

Real-World Git: A Scenario From Start to Finish

We've covered a lot of ground. Let's try to connect some of this information with a real-world scenario that you might encounter!

Suppose you're managing an inventory of server hardware. To keep track of the inventory, you've created a text file with all the necessary details. Now, you're about to overhaul the format of this file to make it more readable. But, you want to try out a few different formats, and also let your team contribute their ideas.

1. Create a Remote Repository on GitHub: You hop over to GitHub and create a new repository called "server-inventory".

2. Clone Your GitHub Repository: Back on your local machine, you navigate to the directory where you want your project to reside. You clone your new repository with git clone [your-repo-url].

3. Create Your Initial File: In the local repository, you add your existing inventory file, inventory.txt.

4. Stage and Commit Your Initial Version: You stage the initial file with git add inventory.txt, and commit it with git commit -m "Initial version of the inventory." 

5. Push Your Initial Commit: Next, you push your initial commit to the remote repository with git push origin main.

6. Create a New Branch: Ready to explore a new format, you create a new branch called table-format using git checkout -b table-format. Now you can experiment without affecting your main branch.

7. Make and Commit Changes: You modify inventory.txt, switching it to a table format. Then you stage and commit your changes with git add inventory.txt and git commit -m "Switched inventory to a table format."

8. Push Your New Branch: You push your new branch and its commits to the remote repository with git push origin table-format.

9. Encounter a Merge Conflict: Meanwhile, one of your team members has created another format in a different branch and merged it into main. When you try to merge your table-format branch into main, you encounter a merge conflict.

10. Resolve the Merge Conflict: You pull the changes from the remote repository with git pull. Git shows you that there's a conflict between your local main branch and the remote one. You open inventory.txt, choose the parts of each format you prefer, and commit the resolved conflict.

11. Merge Your Changes: With the conflict resolved, you merge your table-format branch into main with git checkout main and git merge table-format.

And there it is! You've successfully navigated a real-world Git scenario, from initializing a repository to handling branches and merge conflicts, and finally integrating your changes. Now, let's further connect why git is so important and provide some context for ourselves as SysAdmins & Devops Engineers.

----------

How Does This Help Me?

Git is a foundational skill to learn in the Devops space simply because so much of what we work with can be rendered as text. Scripts, server inventories, server configurations; the list goes on and on. And in those instances where something CAN'T be represented as text, it can usually be CONVERTED to a text representation.

That is exactly what has happened with so many of the most popular Devops tools on the market. Tools like Ansible, Chef, Terraform, Docker, Kubernetes, Github Actions, Jenkins, and Gitlab all use text to represent desired states of your infrastructure or CI/CD pipelines. This means that you can track, version, and modify it within a Git repository!

I truly wish I had learned Git so much earlier in my career. I can't imagine how many Powershell, bash, and Python scripts have been lost to time and hard drives that failed. Books, songs, entire academic courses, and documentation (technical and other) can all be stored in Git to give a running history and allow many people to work asynchronously on a project.

----------

Some Resources

And my personal favorite!

There are hundreds of resources available but getting in there and practicing is the key to success! Hopefully, this series and these resources will be helpful!

With all that said, I want to address something holding you back that you may not be consciously aware of. Let’s talk about the Growth Mindset next time! Until then...

Keep learning and keep growing!

Darrell

Reply

or to participate.