Source control is one of the core strategies for DevOps since having developers and operations team members have access to each others processes require a copy of the code and configurations available to everyone involved.
Whether you write code or just have files you continually have to revise, we need to store our files and keep copies safe.
Git provides a solution for source control and collaboration. In fact one of the largest collaborative open source platforms GitHub is built on GIT. They were recently acquired by Microsoft for over 7.5 Billion dollars.
The Problem that GIT addresses.
When I was starting out and didn’t know any better (some people say I still don’t), I would make a copy and store it in a directory. I also may store a new file with a updated name like Original.txt. I would then have a copy named Originalv2.txt Originalv3.txt as I kept making changes and updates to my file.
However, this over time became quite messy to look at and confusing after a short time.
Further, if I wanted to share this group of files with someone, I would have to tar or zip the file up and send it.
On top of this, if I’m working with someone to make changes, they would send me a file and hopefully, I add it to the right place in the project…this gets very inefficient.
This is where source control comes in.
There are many different solutions such as subversion, mercurial, etc, we’ll focus on Git.
What can Git do?
Linus Torvalds and the developers of the Linux kernel needed to replace their proprietary source control software (BitKeeper) and he made a request to the community of developers to create a source control software that had the following requirements:
Open source and free
Distributed not centralized
Able to work offline
Git is Open Source and free. Enough is said, If you need to make changes to the code to the program, you can. Further, there is no fee to pay for the software. Support is available from a large and active community.
Distributed not centralized. Everyone has a copy of the files. If you need to see the code that is written or a configuration file, it’s right there.
Able to work offline. Changes can be made locally and on a central repository. You can work offline with Git. Make changes to your files and commit them both offline and on the network. Many source control systems don’t allow for offline support.
You need source control as you write code. You may make a mistake and need to roll back. Your system may be running abnormally and your files may end up corrupted… but fear not! You made a backup of that program file…or did you… Maybe its an older backup that you need to recover your code from…how far back…
This is where Git is very useful to have. You can make a local revision backup of your program.
Rather than explaining how it works, go and download a copy of Git.
Get git here
or use Chocolaty
$ choco install git
Git supports a variety of ways to setup a repository.
Local, HTTP/HTTPS (smart with authentication and dumb),SSH/SCP
In this article, we’ll cover local.
Setup local repository for your own files
$ git init
$ git add file1 file2 file3 …
$ git *
$ git commit -m ‘initial commit’
You can upload your files to a remote repository, clone a remote repository and have this used in a DevOps environment. It works very well with Continuous Integration/Continuous Deployment where you can setup a tool like Jenkins to start processing the code out of your repository as soon as there is a change.
For more info on Git, download the book ProGit free in e-book format.
Suggestions and ideas for using Git.
Lastly, what good is knowing about a tool without knowing how you can use it?
Many people have found other ways to use Git besides for source control for coding.
Besides using Git for making copies of code on the repository, you can use it for making
backups. People have written articles, books and distributed it using Git.
In systems administration, you can keep critical systems files using Git
I use it for my Vagrantfiles and Ansible playbooks for my systems configurations.
Let me know your comments and suggestions you may have.
Until then, have a good day.