Day 9 : Deep Dive in Git & GitHub for DevOps Engineers

Q1. What is Git and why is it important?

Git stands for Global Information Tracker. It is a type of version control system which 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.

Q2. What is difference Between Main Branch and Master Branch?

The main branch and the master branch in Git essentially serve the same purpose: they are default branches in a Git repository.

  • Master: Historically, "master" has been the default branch name in Git repositories since its inception in 2005.

  • Main: Starting from Git version 2.28 (released in 2020), "main" was introduced as the default branch name. This change was driven by the movement towards more inclusive and neutral language.

Both "master" and "main" function identically in Git. The difference is purely in naming convention and does not affect Git's functionality. Older repositories might still use "master," while newer repositories often default to "main."

Q3. Can you explain the difference between Git and GitHub?

Git is a type of version control system which 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.

GitHub is a web-based platform built on top of Git, the distributed version control system. It provides a centralized service for hosting, managing, and collaborating on Git repositories. GitHub simplifies the use of Git by offering a user-friendly interface, collaboration tools, and additional features like issue tracking, continuous integration, and project management

Q4. How do you create a new repository on GitHub?

Login to your account in Github.com, at right corner there will be a ‘+’ symbol, click on it and you will get option to create a new repository. Click on it and give the name and required details and your new repository will be created

Q5. What is difference between local & remote repository? How to connect local to remote?

Local repository is the repository which is created and managed by your local system where as remote repository is hosted in remote system and in order to work on it , it is cloned in the local system.

Local can be connected to remote repository by using the below command

git remote add origin <remote git url>

The remote url is the url of remote repository hosted in github

Tasks

task-1:

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

Login into your machine and go to your repository and type the below commands to configure your username and email address associated with every commit.

git config - -global user.name “your name”

git config - -global user.email “your email”

task-2:

  • Create a repository named "Devops" on GitHub

  • Connect your local repository to the repository on GitHub.

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

  • Push your local commits to the repository on GitHub

Commands used:

Connect your local repository to the repository on GitHub

git remote set-url origin git@github.com:username/your-repository.git

I had used ssh key for authentication, you can also use personalized token to connect with repo hosted on git hub. Pls refer the below documentation from github on how to setup authentication. We need to set up authentication as accessing repo through password is no longer supported by github

https://docs.github.com/en/authentication

Push your local commits to the repository on GitHub

git push origin master

By mistake I mentioned master in place of main therefore it created a new branch ‘master’ in github remote repo. You need to mention the right branch name where you want to push your changes. After pushing the change from local machine it appeared on github remote repo.