Understanding Version Control: Central vs Distributed Systems and Git vs GitHub
π Introduction:
Have you ever been in a situation where you lost an important piece of code or struggled to maintain different versions of your codebase? If yes, then version control might be the solution you're looking for. In this blog, we'll discuss what version control is, the differences between central and distributed version control systems, and the difference between Git and GitHub.
πΉWhat's Version Control?
Version control is the process of managing and tracking changes made to a file or a set of files over time. It helps to achieve two main objectives: manageability and versioning of code. With version control, you can keep track of changes made to your codebase, collaborate with others, and maintain different versions of your code.
π Difference between Central and Distributed Version Control Systems:
πΉ Central Version Control:
Central version control systems help to maintain the central versioning of code within a central place inside an organization. However, it comes with a risk if the central server went down, then you won't be able to share the code with others. Examples of a central version control system are SVN.
πΉ Distributed Version Control:
Distributed version control systems help to maintain the distributed versioning of code at different locations. So there is no risk of losing the source code, even if the central source code went down. In distributed version control systems, forking helps to maintain multiple copies of the main code at your level and work on it. At the end of the process, you can ask for a pull request (PR) to merge the changes back to the main central repository of the organization. Examples of distributed version control systems are Git & GitHub, Gitlab, and Bitbucket.
π Difference between Git and GitHub:
πΉ Git:
Git is a local-level tool to manage our source code, and it's open source. Even we can build our own central version control system by launching an EC2 server and installing Git on it and managing the other system to sync our source code. Git has several crucial commands, including Git init, Git clone, Git status, Git add filename, Git commit -m "commit_message", Git push, Git pull, Git diff, Git fetch, Git merge, and Git logs.
β Git Commands:
git init
: Initializes a new Git repository in the current directory. Example:git init
.git clone
: Copies an existing Git repository to your local machine. Example:git clone
https://github.com/example/example.git
.git status
: Shows the current state of your Git repository, including any changes that have been made to your files. Example:git status
.git add
: Adds changes made to specific files to the staging area, preparing them for commit. Example:git add index.html
.git commit
: Saves changes made to the Git repository, along with a descriptive commit message. Example:git commit -m "Added new feature"
.git push
: Uploads local changes to a remote Git repository. Example:git push origin master
.git pull
: Downloads changes from a remote Git repository to your local machine. Example:git pull origin master
.git diff
: Shows the differences between two versions of a file or between two branches. Example:git diff HEAD~1 HEAD
.git fetch
: Downloads changes from a remote Git repository without merging them with your local repository. Example:git fetch origin
.git merge
: Combines changes from one branch into another branch. Example:git merge feature-branch
.git branch
: Shows a list of all branches in the Git repository. Example:git branch
.git checkout
: Switches between different branches or commits in the Git repository. Example:git checkout feature-branch
.git log
: Shows a history of all commits made to the Git repository. Example:git log
.
πΉ GitHub:
GitHub helps with usability, issue raising, commenting, reviewing, collaboration, project management, and CI/CD pipelines using GitHub Actions. With GitHub, you can easily collaborate with others, raise issues, communicate through commenting, review code changes, manage projects, and automate your CI/CD pipelines.
π Conclusion:
In conclusion, version control is a crucial tool for managing and tracking changes made to a file or a set of files over time. It helps to maintain different versions of your codebase, collaborate with others, and keep track of changes made to your code. Central and distributed version control systems have their own advantages and disadvantages, and you can choose the one that fits your organization's requirements. Git and GitHub are popular tools for version control and collaboration, and they have unique features and functionalities.