Git for DevOps[Code management]
Table of contents
DevOps depends on the source code management system that is used by the entire team. Code management is a set of software-supported practices used to manage an evolving codebase. We need code management to ensure that changes made by different developers do not interfere with each other and to create different product versions. Code management tools make it easy to create an executable product from its source code files and run automated tests on that product. Source code management, combined with automated system building, is critical for professional software engineering. In companies that use DevOps, a modern code management system is a fundamental requirement for “automating everything.” Not only does it store the project code that is ultimately deployed, but it also stores all other information that is used in DevOps processes.
Git-Introduction
Git is a version control system that is widely used for software development and version control. It allows multiple developers to work on the same codebase simultaneously and track changes made to the code over time.
In 2005, Linus Torvalds, the developer of Linux, revolutionized source code management by developing a distributed version control system (DVCS) called Git to manage the code of the Linux kernel. It is designed to manage an evolving project codebase to allow different versions of components and entire systems to be stored and retrieved. Developers can work in parallel without interfering with each other and they can integrate their work with that of other developers.
One of the key features of Git is that it tracks the history of changes made to the codebase. This allows developers to see who made changes, when they were made, and what those changes were. It also makes it easy to roll back changes if necessary.
Git provides a set of features that support four general areas:
Code transfer:- Git uses a distributed version control system, which means that each developer has a copy of the entire codebase on their local machine. This allows them to work on the code offline and commit their changes to their local repository. When they are ready to share their changes with other team members, they can push their changes to a remote repository, such as a server hosted on GitHub or GitLab.
Version storage and retrieval:- Files may be stored in several different versions, and specific versions of these files can be retrieved.
Merging and branching:- Parallel development branches may be created for concurrent working. It allows developers to create separate copies of the codebase and work on them independently. This is useful for creating new features or experimenting with different approaches without affecting the main codebase. Changes made by developers in different branches may be merged.
Version information:- Information about the different versions maintained in the system may be stored and retrieved.
Basic git commands
git init //initialize a new git repository in the current directory
git clone <rep url> //create a local copy of a remote repository
git add <filename> //to add a change to the staging area
git add --all //add all files in that folder
git status //to show the status at present
git log //to get details of commit history
git commit -m"<message>" //to commit the changes into git folder
git checkout <id> //to move to different updates
git pull <remote> <branch> //pull latest changes from specified remote repository and merge them into current branch
git push <remote> <branch> //push latest changes to remote repo
git diff //view difference bw stagged changes and resent commit
git branch <name> //creates new branch
git merge <name> //merges a branch to master
Git is a powerful tool that is widely used in the software development community. It allows teams to collaborate effectively and track the history of their codebase as it evolves.