Basic Git & GitHub for DevOps Engineers

Basic Git & GitHub for DevOps Engineers

Git:

Git is a distributed version control system used for tracking changes in source code during software development. It allows multiple developers to collaborate on a project, keeping a history of changes and facilitating the merging of different code branches.

What is Github?:

GitHub is a web-based platform that provides hosting for version control using Git. It is a subsidiary of Microsoft, and it offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its own features. GitHub is a very popular platform for developers to share and collaborate on projects, and it is also used for hosting open-source projects.

What is Version Control? How many types of version controls we have?

Version control is a system that tracks changes to a file or set of files over time so that you can recall specific versions later. It allows you to revert files back to a previous state, revert the entire project back to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.

Version control is a system that records changes to files over time, enabling you to track and manage different versions of a project. It helps in collaboration, allowing multiple contributors to work on the same codebase without conflicts.

Types of Version Control:

  • Cntralized Version Control (CVCS):

This involves a central server that stores the repository, and multiple clients that check out and update code from that central place. Examples include CVS and Subversion.

A centralized version control system (CVCS) uses a central server to store all the versions of a project's files. Developers "check out" files from the central server, make changes, and then "check in" the updated files. Examples of CVCS include Subversion and Perforce.

  • Distributed Version Control (DVCS):

    In this model, each user has their own local repository, and changes are synchronized between repositories. Git and Mercurial are examples of distributed version control systems.

    A distributed version control system (DVCS) allows developers to "clone" an entire repository, including the entire version history of the project. This means that they have a complete local copy of the repository, including all branches and past versions. Developers can work independently and then later merge their changes back into the main repository. Examples of DVCS include Git, Mercurial, and Darcs.

Why we use distributed version control over centralized version control?

  • Better collaboration:

    In a DVCS, every developer has a full copy of the repository, including the entire history of all changes. This makes it easier for developers to work together, as they don't have to constantly communicate with a central server to commit their changes or to see the changes made by others.

  • Improved speed:

    Because developers have a local copy of the repository, they can commit their changes and perform other version control actions faster, as they don't have to communicate with a central server.

  • Greater flexibility:

    With a DVCS, developers can work offline and commit their changes later when they do have an internet connection. They can also choose to share their changes with only a subset of the team, rather than pushing all of their changes to a central server.

  • Enhanced security:

    In a DVCS, the repository history is stored on multiple servers and computers, which makes it more resistant to data loss. If the central server in a CVCS goes down or the repository becomes corrupted, it can be difficult to recover the lost data.

  • Branching and Merging:

    DVCS excels at branching and merging, making it easier for developers to create isolated features or experiments and then seamlessly integrate them back into the main codebase. Git's branching capabilities are a notable example of this.

  • Redundancy and Backup:

    Every user's local repository in DVCS is a complete copy of the project, providing redundancy. If a central server fails in CVCS, it can be a single point of failure. In DVCS, multiple copies of the repository exist, reducing the risk of data loss.

What is difference Between Main Branch and Master Branch??

The terms "main" and "master" are often used interchangeably in Git to refer to the default branch in a repository. However, there has been a movement in the tech industry to move away from the term "master" due to its historical association with slavery.

To promote more inclusive language, some Git hosting services and projects have started using "main" instead of "master" as the default branch name. GitHub, for example, now creates repositories with the default branch named "main."

So, in practice, there is no functional difference between "main" and "master" branches in Git. The choice of terminology depends on the conventions followed by the project or organization. It's recommended to check the specific guidelines or preferences of the project you're working on to determine which term is used for the default branch.

What is difference Between Git and GitHub?

Git:

  • Definition:

Git is a distributed version control system designed for tracking changes in source code during software development.

  • Functionality:

Git allows developers to work collaboratively on projects by managing and tracking changes to the source code. It provides features like branching, merging, and history tracking.

  • Local Repository:

Git operates locally on a developer's machine, allowing them to make changes and commit them to their local repository.

  • Usage:

Git is used for version control in various development environments, whether solo or in teams. It is especially useful for managing codebases, tracking changes, and collaborating on software projects.

GitHub:

  • Definition:

    GitHub is a web-based platform that provides hosting for software development and version control using Git.

  • Functionality:

    GitHub extends the capabilities of Git by offering a centralized platform for hosting repositories, collaboration, issue tracking, and more. It adds a social and web-based interface to Git.

  • Remote Repository:

GitHub hosts remote repositories, enabling multiple developers to collaborate on a project. Developers can push their changes to GitHub and pull changes from others.

  • Collaboration:

GitHub facilitates collaboration through features like pull requests, issues, and project management tools. It allows developers to contribute to open-source projects and collaborate on private repositories.

What is difference between local & remote repository?

Local Repository:

  • Definition:

A local repository is a copy of a Git repository that is stored on a developer's local machine.

  • Functionality:

It contains the complete version history of the project and allows developers to make changes, commit them, and manage versions locally.

  • Operations:

Developers can work independently in their local repository, creating branches, making changes, and committing those changes without affecting the shared version of the project.

  • Advantages:

Working locally is faster, and it provides flexibility for experimenting with new features or changes before sharing them with others.

Remote Repository:

  • Definition:

A remote repository is a copy of a Git repository that is hosted on a server, often on a platform like GitHub, GitLab, or Bitbucket.

  • Functionality:

It serves as a central hub where multiple developers can collaborate, share changes, and contribute to the project. Remote repositories store the shared version of the project.

  • Collaboration:

Developers push their changes to the remote repository, allowing others to pull those changes into their local repositories. This enables collaboration and ensures a centralized location for the latest version of the project.

  • Backup and Redundancy:

Remote repositories provide a backup and redundancy for the project, reducing the risk of data loss. They also serve as a common reference point for the entire development team.

Tasks:

  • Task1:

Install Git on your computer (if it is not already installed). You can download it from the official website at

https://git-scm.com/downloads

  • Task2:

Create a free account on GitHub (if you don't already have one). You can sign up at

github.com

  • Task3:

Create a repository named "Devops" on GitHub

Go to the Guthub Account. After that go the Repository section, Click to new add button and Fill the portal

  • After that click the create repository button. When you clieck the button it will show.

  • Task4:

    Create the user name and Email for your ubuntu machine, Create the Directory or Files, Connect local repo to remote repo, push the all code for local repo to remote repo

Set your user name and email address, which will be associated with your commits.

Create a new file in Devops/Git/Day-02.txt

Press the enter button and vi editor is open, write the some lines.

Press the ESC button type :wq for exit the Vi editor.

Day-02.txt the file is belong to Working stage, we will go to the Staging area then we write the command git add <file_name>

For check the status, we type the code git status

After that we will go to local repo, type the code commit -m "<message_name>"

After that we check commit is ok or not?

when we have recevied working tree clean that is mean, commit is done you can push the code remote repo. So for push the code first we connect the local repo to remote repo. So the command is

Copy the url for github

Copy the https url and click the enter button, After that they will ask uder id and password, For password we have to generated the token,so we use the token.

git push origin master command we use push the code to github. If you want to see the file so you can go to github account and refresh the github account, then you will se the text file.

Now we type git log for ubuntu machine, this command is show how many commit you have done.

Now we have only done one commit,also they provide you commit Id(6498c2d1716b9a9833472c09c8fffa7bd5d082ca), So commit Id is so important as a developer.