What is git?
Git is a distributed version control system (DSVC). Like any other version control. git provides all basic features to work on a source tree with many developers. Git is very popular for its features. Was originally developed by Linus Torvalds, for Linux kernel development. For a larger scale of software development, a subversion control system (SVC) is highly effective for parallel development, Track changes, branching, merge, etc. A central copy of code is maintained called repository.
For example, in a company there are 10 software developers, working on the same project, in parallel, each developer developing a module of a big project. Once a feature is completed in software,(e.g developed, git commit and git push ) by one developer new feature will be automatically available to other developers. If SVC is not used, other developers have to take/merge the code manually.
In case of conflict (at the same place in code two developers has written) between two development, the version control (VC) shows both the codes and developers can manually merge (select correct code) and can update (git push) in the central repository. VC maintains a set of files for a version, any point of time the set of files can be retrieved. When any change in SVC is made ( source file is added or modified) the version number changes or advances.
Central, version control (SVC): A central copy called 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 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 available to other users the central copy is updated (git push command). Other users can update local copy by git pull.
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 in the local repository and not available to other users. When code changes need to updated on 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 is the current local repository.
- git revert command performs undo changes.
- git add command prepare the staging area for 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.
- Distributed in nature, 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.