Deep Dive in Git & GitHub for DevOps Engineers: Part-2

Deep Dive in Git & GitHub for DevOps Engineers: Part-2

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:

  • Centralized- All team members connect to a central server to get the latest code copy and share their contributions with others.
  • Distributed- In a distributed VCS, every team member has a copy of the project and its history on their machine, allowing them to save?snapshots?of the project locally.

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.

No alt text provided for this image

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.

No alt text provided for this image

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.?

No alt text provided for this image

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

No alt text provided for this image

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?

  1. First, git should be installed on your local machine. To install git follow the link
  2. Check git install or not using the command git --version or git -v
  3. Create a local directory and go into that dir to make this dir as a local git repository
  4. First, we have to turn the local dir into a Git repository. The default behavior of?git init?is to transform the current directory into a Git repository. For an existing project to become a Git repository, navigate into the targeted root directory. Then, run?git init.
  5. To connect the local repository to the git remote repository use the below command. A git remote command is used to make the remote connections such as connecting the local repository to the remote repository

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

  • Tell git who you are by configuring the author name

git config --global user.name "<Your-Username>"

  • Tell git who you are by configuring the email id

git config --global user.email "<Your-Email-Address>"

No alt text provided for this image

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

No alt text provided for this image
No alt text provided for this image

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

No alt text provided for this image

Here use?the git remote?command to connect the local repository to the GitHub repository.

git remote add origin <URL_from_GitHub_repository>

No alt text provided for this image

3. Create a new file in Devops/Git/Day-02.txt & add some content to it.

No alt text provided for this image
No alt text provided for this image

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

No alt text provided for this image
No alt text provided for this image

Thank you for reading the article.

Happy Learning!

要查看或添加评论,请登录

社区洞察

其他会员也浏览了