Basic Git & GitHub for DevOps Engineers.

Basic Git & GitHub for DevOps Engineers.

What is Git?

  • Git is a version control system that allows you to track changes to files and coordinate work on those files among multiple people. It is commonly used for software development, but it can be used to track changes to any set of files.

  • With Git, you can keep a record of who made changes to what part of a file, and you can revert back to earlier versions of the file if needed. Git also makes it easy to collaborate with others, as you can share changes and merge the changes made by different people into a single version of a file.

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

  • here are two main types of version control systems: centralized version control systems (CVCS) and distributed version control systems (DVCS).

    Centralized version control systems (CVCS)

    Distributed version control systems (DVCS).

    CVCS uses a central server to store all the versions of a project's files.

    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, In the local system.

    Developers "check out" files from the central server, make changes, and then "check-in" the updated files.

    Developers can work independently and then later merge their changes back into the main repository.

    Examples of CVCS include Subversion and Perforce.

    Examples of DVCS include Git, Mercurial, and Darcs.

Why do we use distributed version control over centralized version control?

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

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

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

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

Overall, the decentralized nature of a DVCS allows for greater collaboration, flexibility, and security, making it a popular choice for many teams.

Install Git

  • sudo apt install git

  • Here are the steps to install Git on Windows:

    1. Go to the Git website: git-scm.com/download/win

    2. Click the "Download" button.

    3. After the download is complete, run the .exe file to start the installation process.

    4. Choose the components you want to install. If you're not sure, leave the default settings and click "Next".

    5. Choose the installation location. Again, if you're not sure, leave the default setting and click "Next".

    6. Select the option "Use Git from the Windows Command Prompt" and click "Next".

    7. Choose the default editor used by Git. You can use the default or choose a different editor, then click "Next".

    8. Choose the default branch name for new repositories. You can use the default or choose a different name, then click "Next".

    9. Choose the default behavior for line endings. Again, you can use the default or choose a different setting, then click "Next".

    10. Choose the terminal emulator used by Git Bash. You can use the default or choose a different emulator, then click "Next".

    11. Choose whether to enable Git Credential Manager, which provides secure storage for Git credentials. If you're not sure, leave the default setting and click "Next".

    12. Choose whether to enable symbolic links for Git repositories. If you're not sure, leave the default setting and click "Next".

    13. Review your settings and click "Install".

    14. Wait for the installation to complete.

    15. Click "Finish" to complete the installation.

After completing the installation, you can use Git from the Windows Command Prompt, Git Bash, or any other Git-enabled terminal.

Create a free account on GitHub

  • Steps to create a GitHub account:

    1. Go to the GitHub website: github.com

    2. Click the "Sign up" button in the top right corner of the page.

    3. Choose a username for your account.

    4. Enter your email address and a strong password.

    5. Click the "Create account" button.

    6. Select your preferred plan. You can choose between a free plan or a paid plan with additional features.

    7. Fill out the "Tell us about yourself" section. This is optional, but it can help other users find and connect with you.

    8. Verify your email address by clicking the verification link sent to your email.

    9. Complete the setup process by customizing your profile and setting

Create a new repository on GitHub and clone it to your local machine

1) Create a new repository on GitHub and clone it to your local machine

--> Create a new repo, copy the link of the repo and use the git clone command to clone it in your local

sudo git clone <git-repo link>

2) Make some changes to a file in the repository and commit them to the repository using Git

  • sudo git init

    Logically divided the local directory into a three-part working directory, staging area, local repo

  • Working directory

    where you see files physically & do modification

  • sudo git add .

    adds changes to a file or directory to the staging area, which is a temporary storage area for changes that are not yet committed to the repository. Once changes have been added to the staging area using git add, they can be committed to the repository using the 'sudo git commit'

  • git commit is a command in the Git version control system that creates a new commit in the repository, recording the changes that have been added to the staging area.

Push the changes back to the repository on GitHub

  • sudo git push -u origin

    'push' operations copy changes from a local repository instance to a remote or central repo. this used to store the changes permanently in git.

Go to GitHub and check devops file is already there with its content