Deep Dive in Git & GitHub for DevOps Engineers

Deep Dive in Git & GitHub for DevOps Engineers

Day 9 of 90daysofdevops

What is Git and why is it important?

  • Git is a free, open-source, popular distributed version control system that allows developers to collaborate on software development projects for tracking code changes.

  • The importance of Git are followed:

  1. Git allows developers to work on code simultaneously and merge changes made by different team members easily.

  2. Git provides a complete history of all changes made to the codebase, including who made the changes and when. So if required we can revert the code changes.

  3. Git makes it easy to manage multiple branches of code, allowing developers to experiment with new features or fixes without disrupting the main codebase.

What is the difference Between Main Branch and Master Branch?

  • The "master" branch was traditionally used as the default main branch for a repository. However, in recent years there has been a movement to replace the term "master" with more neutral and inclusive terms like "main" or "default".

  • There is no functional difference between a "main" branch and a "master" branch in Git. The "main" serve as the long-lived, stable branch which is the default branch for a repository, from which other branches can be created and changes can be merged.

Can you explain the difference between Git and GitHub?

  • Git is a free and open-source distributed version control system designed to manage and track changes in source code during software development.

  • GitHub, on the other hand, is a web-based hosting service that provides a platform for software developers to collaborate on Git repositories. It offers additional features on top of Git, such as bug tracking, task management, and code review tools.

How do you create a new repository on GitHub?

To create a new repository on GitHub, follow these steps:

  1. Go to the GitHub website and log in to your account.

  2. Click the “+” icon in the top right corner of the screen and select “New repository”.

  3. Enter a name for your repository in the “Repository name” field.

  4. Optionally, you can add a description of your repository in the “Description” field.

  5. Select whether you want your repository to be public or private. Public repositories are visible to anyone and can be cloned or forked by anyone, while private repositories are only accessible to you and other people you specifically invite.

  6. Choose a license for your repository.

  7. Click the “Create repository” button.

What is the difference between local & remote repositories? How to connect local to remote?

  • A local repository is a copy of the repository that is stored on your own computer. You can then make changes to the files in the repository, commit those changes, and push them back up to the remote repository without the Internet.

  • A remote repository is a repository that is hosted on a remote server and can be accessed from anywhere using the internet. When you push changes to a remote repository, those changes are stored on the remote server and others can view those changes.

  • To connect a local repository to a remote repository in Git, you can follow these steps:

  1. Create a remote repository in remote repository that is GitHub

  2. Next, initialize a local repository on your computer using the "git init" command.

  3. Copy the URL of the remote repository.

  4. In your local repository, run the below command to add the remote repository:

     git remote add origin <remote_repository_URL>
    
  5. Finally, push your changes to the remote repository using the "git push" command

     git push -u origin master
    

    Note: The -u option is used to set the upstream branch, which means that Git will remember the remote repository and branch you pushed to, and you can simply use git push in the future to push changes to that branch.

Task 1:

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

git config — global user.name "Your Name"

git config — global user.email "dummy@email.com"

  • Commit the file and view the git log to display the username and email.

Task 2:

  • Create a repository named "Devops" on GitHub

  • Connect your local repository to the repository on GitHub.

    Initially, clone the repository.

    Creating a file "Day-02.txt" in the folder

  • Push your local commits to the repository on GitHub

Thank You,

Abhisek Moharana