What is git? A version control system.
Git is a version control system that is distributed (DSVC). As with any other version control tool, git has all of the functionality you’ll need to collaborate on a shared source tree with multiple developers at the same time. Git is well-known for its capabilities. Linus Torvalds created it for the development of the Linux kernel.
Why do we need a source code version control system?
A subversion control system (SVC) is particularly effective for parallel development, tracking changes, branching, merging, and other tasks on a wider scale of software development. A repository is a central copy of code that is kept.
For instance, ten software developers in a company are working on the same project simultaneously, each building a module of the project. One developer completes a feature in software (e.g., developed, git commit, and git push).
Other developers will have access to the new feature automatically. Other developers must manually take/merge the code if version control is not employed.
When two sub-developments have conflicts (at the same place in the code that two developers have produced), the version control (VC) reveals both works, and developers can manually integrate them (select correct code).
They can push changes to the central repository (using the git push command). When any change in SVC is made (source file is added or edited), the version number changes or advances, and VC retains a collection of files for a commit. The set of files can be retrieved at any time.
Type of Version Control tools:
Central Version Control (CVC): A central copy called a repository is maintained on a machine. If any user commits the changes, the central copy is updated.
Distributed SVC: Every user has a full copy of the repository (git clone command creates) on a local machine, along with a central or remote repository. The local copy has a full history of changes. All operations (branching, merging, etc.) can be done on a local copy, so even if there is no internet access, all SVC things can be done. When a commit (git commit) is done, it changes the local repository copy. If the changes have to be available to other users, the central copy is updated (git push command). Other users can update local copy by git pull.
List of useful Git commands :
- git init creates a new repository.
- Git merge – command merges the code from a branch to the current working branch. If the git merge gives conflicts, then conflicts should be resolved manually.
- Git clone– command creates a full copy of the repository on a local machine. The local repository has a full history of all changes.
- Git push – command if a user makes changes and does commit. Changes go into the local repository and are not available to other users. When code changes need to be updated on the central repository, git push is used. After a successful git push, other developers can update the local copy.
- Git checkout command enables the user to switch from one branch to another or to create a new branch and switch to the new branch. The git branch can list all branches, and git checkout use can switch to a branch.
- Git pull – command updates the local copy from the central repository. It does code download and does git merge.
- Git branch command displays all branches in the current local repository.
- Git revert command undoes changes.
- git add command prepare the staging area for the next commit
- A full git repository can be recovered from any local repository in case of central repository failure.
- Branches are lightweight in git, as they have only reference for change codes, not the full copy.
- There is a staging area in git. This area can be prepared for the next commit. Can add files or directories for the next commit.
- It is distributed in nature, and highly effective for parallel development. Offline users can also take full advantage of a source control system.
- Accountability, git does details logging for every commit. A user who commits can be traced easily.