VERSION CONTROL
Welcome to the blog of Git vs Github
VERSION CONTROL
An explanation of what Version Control is, July 5, 2021
Version Control, also known as source control, is the practice of tracking and managing changes to software code.
Version control systems are software tools that help software teams manage changes to source code over time. They are especially useful for DevOps teams since they help them to reduce development time and increase successful deployments.
Version control software keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members.
When working in teams, software developers have different tasks, but need to work on the same code base. The code for a project, app or software component is typically organized in a folder structure or "file tree". One developer on the team may be working on a new feature while another developer fixes an unrelated bug by changing code, each developer may make their changes in several parts of the file tree.
Some of the functions of Version Control Software include:
- Version Control comes in to keep track of every individual change made.
- It helps coordinate the merging together of the different editted files into the project.
- It helps prevent concurrent work from conflicting when merged back into the entire project.
Some examples of version control systems (VCS) include:
- Git Initial Release: 2005
- Apache Subversion Initial Release: 2000
- Mercurial Initial Release: 2005
- Azure DevOps Server Stable Release: 2020
GIT
What is git, July 5, 2021
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Git was created by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development.
Git Install instructions: Get Git!
GIT COMMANDS
To check version of git installed (It will also confirm that git is installed properly):
$ git --version
To add a local git repository (the .git repository) to your current directory:
$ git init
Checking in: This is the process of uploading code to the master branch for an admin to check and update the project. It involves staging and committing.
Staging: This is the required intermediate step in checking in a file, and involves collecting the changes to be added to the repository. This allows for logically different changes to different files to be added to the repository in different commits.
To stage files before committing to the repository, the files(eg "fileName1.txt" and "fileName2.html") are added to the staging area:
$ git add fileName1.txt fileName2.html
Committing: Capturing a snapshot of the project's currently staged changes. These versions can be thought of as "safe" versions of the code. When troubleshooting problems, changes between commits are to be looked into.
To commit changes in the staging area and adding a commit message(eg "Added feature XYZ"):
$ git commit -m "Added feature XYZ"
Status: It is sometimes necessary to know what files are staged and ready for committing. If any changes have been made to the files and need to be added to the staging area. if the git repository is up-to-date... And many more. This is done by checking the status.
To check the status of the git repository:
$ git status
Branching: A branch is nothing but a pointer to the latest commit in the Git repository. Branching is used to support multiple parallel developments. Especially when testing in order to avoid causing problems with the main code base.
Creating a new branch (eg "branchName"):
$ git branch branchName
Switching a different branch (eg "branchName"):
$ git checkout branchName
Listing all the branches::
$ git branch
Merging: After a branch has diverged from the master branch(ie the two branches have different code), the code of the second branch can be brought back. This is called merging.
To merge a branch back to the master branch, call the checkout command from the master branch:
$ git checkout master
$ git merge branchName
GITHUB
Github as a remote git repository, July 5, 2021
Github is a provider of internet hosting for softwre development. It allows developers to store their projects online.
Github is highly integrated with git(the command-line tool installed on the developer's machine), allowing the software developer to have access to remote repositories.
Each developer will work in their local repository but eventually, they will push the code into a remote repository. Once the code is in the remote repository, other developers can see and modify that code (as illustrated)
Create a github account: Join Github!
GIT REMOTE REPO COMMANDS
Pointing the local repository to a remote repository and naming the remote repository( name: "origin"):
$ git remote add origin [remote repo URL]
Pushing all the code from the local repository (master branch) into the remote repository(previously created "origin"):
$ git push -u origin master
Pulling the latest changes from the remote repository into the local repository:
$ git pull origin master
Cloning an existing remote repository into your computer:
$ git clone [remote repo URL]