Just enough git for Puppet automation – Part1
+ summary of this article :
All Posts in this Series
- Just enough GiT for Puppet Automation – Part1
- Just enough GiT for Puppet Automation – Part2
- Just enough GiT for Puppet Automation – Part3
- Just enough GiT for Puppet Automation – Part4
- Just enough GiT for Puppet Automation – Part5
- Just enough GiT for Puppet Automation – Part6
- Just enough GiT for Puppet Automation – Part7
What is Version Control?
If you haven’t used Git, or a similar version control tool (CVS and Subversion are some other examples), you might be wondering what it is and why we should use it.
Even if you’re the only person who works on a piece of source code (for example, Puppet manifests), it’s still useful to be able to see what changes you made, and when. For example, you might remember that you fixed a bug last week, but not exactly how, and it would be handy to be able to see exactly what lines in which file were changed.
Imagine you’re trying to track down a bug; having a complete history of code changes would be a big help. It also means you can, if necessary, roll back the state of the code to any point in history and examine it.
You might think this introduces a lot of extra complications. In fact, it’s very simple. Git keeps out of your way until you need it, and all you have to do is write a commit message when you decide to record changes to the code.
Another very important role of version control is to allow several people to work independently on the code, and to merge all their separate changes back together and resolve any conflicts. Git provides very powerful tools for doing this. If you’re working on Puppet code in a team, it’s critical that you use some kind of version control to handle it.
Why version control?
Version control is very useful for tracking changes to any source code, including Puppet manifests. It’s especially important when several people are working on the same code, so that they can communicate with one another about their changes. Version control can also detect and alert you to conflicts when the same file is edited by different people independently.
Getting started with Git
Git first time Usage in 3 Simple Steps:
1. you create a repo using the command – git init
2. make an initial snapshot using the command – git add
3. Save your changes using the command – git commit
Common commands for Git daily usage:
Thereafter, every time you want to record a set of changes
1. Once you make modification to your files run – git add
2. And to store them with an appropriate message, run – git commit
Git Command to track the changes :
1. As you’re working on a set of changes, you can see how the current code differs from Git’s stored version using – git diff
2. To show which files Git thinks may need to be committed, run the command – git status
3. You can see the complete history of changes to your repo using the command – git log
4. To show you the differences in each file before and after the commit run – git whatchanged