What is Git?
Git is an open-source distributed version control tool designed to handle everything from small to very large projects with speed and efficiency. It was created by Linus Torvalds in 2005 and has since become one of the most widely used version control systems in the software development industry.
In simple words, Git is used to track code changes in their codebase.
With the help of Git, you can track who made the changes, when changes were done, and why the changes were made and if the changes are not working expectedly you can revert your code to the previous version with a version tracking system.
Why Git is so Important for Developers and DevOps Engineers.
Git is so important for Developers because of multiple benefits as below.
Version Control: Developers can easily manage their code and track the changes in the code and make the decision as per the code behavior without affecting the code base and avoiding conflicts.
Collaboration: Git allows developers to work on the same file/code with multiple developers at the same time even if they are working from any destination in the world.
Backup and Recovery: Git allows keeping your base code safe because of distributed version control system and you can take back up and recover your code in case of any code corruption incident happen.
Code review: Git has provided an amazing facility that is Code Review, you can request your Team members to review your code if it is meeting the organization's code standard or not before pushing the code to the main branch.
Branching and Merging: Git provides the facility to create a new branch of your code if you want to add a new feature or need to fix any bug in this case you can create a new branch and work on your feature and complete your task you may merge it to the master branch.
How do you create a new repository on GitHub?
We have very easy steps to create a new repository on GitHub.
I hope you already have an account on GitHub below are the screenshots to help you.
Step 1 : Click on the green color New button
Step 2 : Provide the repository's name and select the radio button accordingly if you want to make this repository public or private.
Step 3 : Save the repository by the clicking on Create Repository button.
Your Repository is ready.
Difference between local and remote repositories.
Local Repository: Local repository is stored on your local machine or we can say a repository that contains code in the local machine or any server where you can work and research and add features and debug the code independently and can work without the internet and you can commit your code and make the changes as per your convenience without effecting codebase that is stored in Remote or GitHub.
Remote Repository: Remote repository is the repository that host or is stored in remote servers like GitHub, GitLab or BitBucket you work with the team and can get the latest version of code and also collaborate with developers who may review your or your team's code.
In summary, the main difference between a local and remote repository is that a local repository is stored on your computer and allows you to work on your code locally, while a remote repository is stored on a remote server and allows for collaboration and version control among team members.
How to connect from local to Remote
To make the connection from your machine to GITHUB or push the files from local to GIT HUB below are the steps
Create a repository on GIT HUB if not created, then copy the HTTPS URL of the repository from GIT HUB
Come to your local machine command prompt and type the below command along with your HTTPS URL.
$ git remote add origin https://github.com/.../direc.git
//main command is git remote add origin after it URL
You will be able to connect.
How to push a file to my created repository.
Let me create a Test file on my terminal.
$ vim Test.txt
// content
This is Test file to test how to push to GitHub
Now I want to push this file to my DevOps repository.
Here is the command for the same.
git add . // stage the file
git commit -m "push message" //commit your changes
git push origin master // your changes will be push to Master branch
You will similar kind of structure on GitHub
Happy Learning
Saif Ali