Deep Dive in Git & GitHub for DevOps Engineers: Part-2
Deepak Patil
DevOps engineer with 3+yrs DevOps/ DevSecOps/ Cloud Experience in AWS?? | DevOps ?? Technologies ?????? Linux ??? | Git ?? | Terraform?? | Docker ?? | Kubernetes | EKS | HELM | ? | Jenkins ???.
What is Git and why is it important?
Git is a free, open-source VCS used for?tracking source code changes. It allows multiple developers to work together on?non-linear development. Git is free, open-source, speedy, and scalable, making it the world's most popular VCS.
There are two types of version control systems:
The issue with a centralized VCS is the single point of failure. If the server goes down, team members can't collaborate or save snapshots of their projects.
Git is a distributed VCS that?resolves the single point of failure?issue because it allows members to synchronize their work even if the central server is offline.
Why is it important?
Git's primary use is?source code management?in software development, however, it can track changes in any file set. The project history stored in Git shows who has made changes, what was done, when, and why.
Being a distributed VCS, Git enables every team member to have a copy of the project and its history on their machine, allowing them to?save project snapshots locally.
It also allows developers to work with?several remote repositories?and collaborate with other people simultaneously within the same project. Consequently, users can set up?multiple workflow types that aren't possible in a centralized system, e.g., a hierarchical model.
Features:
Several features put Git ahead of other version control systems.
1. Performance
Performance is Git's trump card when comparing it to other version control systems. Committing changes, branching, merging, and comparing previous versions are all highly performant operations in Git.
2. Compatibility
Git is compatible with all the available operating systems, as well as other VCS?remote repositories, which it can access directly.
Its ability to access other VCS repositories means that users can easily?switch to using Git?without moving their files from those repositories to the Git repository.
3. Branching
Branches in Git are development lines parallel with the main project files. By using branches, developers can make changes to the project?without affecting the original version.
The original version stays on the master branch and can later merge with new features after testing them on other branches.
4. Security
Security and code integrity is a priority when committing changes in Git. This VCS?stores records of all the commits?done by each teammate on the developer's local copy. When someone performs a push operation, Git?creates a log file?and sends it to the central repository. Thus, if an issue occurs, it can be easily tracked and resolved.
Another great security feature is the?SHA1 cryptographic algorithm, used to secure and identify all the objects in the repository. The algorithm protects the code and the change history from accidental or intentional changes while ensuring a fully traceable history.
5. Speed
Fetching data from a local repository is approximately 100 times faster than fetching from a remote repository. Git stores all project data?in the local repository, resulting in incredible speeds when fetching data. Git is also highly scalable and faster than other version control systems, allowing it to handle large projects efficiently.
6. Flexibility
Users can easily track changes as developers can leave a?commit message?after making modifications. A commit message enables another developer to seamlessly continue working where the previous one left off.
Git also includes features like Backup and Restore, which help users maintain the source code backup. Additionally, it requires only one command to deploy the source code on the server.
What is the difference Between Main Branch and Master Branch?
There is no difference between the main and master branch in git. The Main or Master branch is a default branch when you create a repository. GitHub now uses?main?as its?default branch. while others still use the master branch as a default branch.
Can you explain the difference between Git and GitHub?
Git:
Git is a distributed version control system, tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development. Git is installed and maintained on your local system. Git is a command-line tool.
GitHub:
GitHub is a cloud-based platform that provides hosting for version control using Git. It is a service we use to store our project files. GitHub is designed as a git repository hosting service. GitHub is a graphical user interface.
How do you create a new repository on GitHub?
To create a new repository on GitHub below are the steps:
1. Go to github.com and log in to your account. (If the account is not created create the git hub free account)
2. In the upper-right corner, Click the " + " and select New repository.?
3. Enter the Name of your repository
领英推荐
4. Enter the repository Description?(optional)
5. Choose whether you want to make your repository public or private
6. Add a README file. This is where you can write a long description for your project.
7. Click on Create repository
What is the difference between local & remote repository? How to connect local to remote?
Git local repository is?the one on which we will make local changes, typically this local repository is on our computer.
Git remote repositories are hosted on a server that is accessible to all team members.?
How to connect local to remote?
git remote add origin https://github.com/YOUR-USERNAME/YOUR- REPOSITORY
Ex. git remote add origin https://github.com/Dips-1991/DevOps-Repo.git
5. git push origin main/master
Task 1:-
1. Set your user name and email address, which will be associated with your commits.
To set the user name and email address associated with the commit we use the below two commands
git config --global user.name "<Your-Username>"
git config --global user.email "<Your-Email-Address>"
Task 2:-
1. Create a repository named "DevOps-Repo" on GitHub.
In the previous section of this article, "How do you create a new repository on GitHub?" we have learned how to created the repository with the steps please follow that section
2. Connect your local repository to the repository on GitHub.
In the previous section of this article, "How to connect local to remote?" we have already learned how to connect the local repository with the GitHub repository with the steps please follow that section
Here use?the git remote?command to connect the local repository to the GitHub repository.
git remote add origin <URL_from_GitHub_repository>
3. Create a new file in Devops/Git/Day-02.txt & add some content to it.
4. Push your local commits to the repository on GitHub.
Git push: The git push command is?used to upload local repository content to a remote repository.
git push origin main/master or git push repo_name
If git asks for Username enter your GitHub Username Ex. Dips-1991 and Password here in my case I will use GitHub Personal Access Token
Thank you for reading the article.
Happy Learning!