Day 12 Task: Deep Dive in Git & GitHub for DevOps Engineers

Day 12 Task: Deep Dive in Git & GitHub for DevOps Engineers

Fundamental Git Practices for DevOps Experts

  1. What is Git and why is it important

    Git is a distribution version control system that tracks changes in source code during development phase. Its an open source tools so multiple developers can allow to communicate, and create a work environment and collaborate with each others to make better versions.

Importance of Git -

  1. Version control - Git is a version control system that allows you to keep a track your changes of the source code in the form of version for better content. You can go back to your older changes or previous whenever you need them.

    It allows developer to work seperately in their tasks by creating another branches of the project and when the task is done they merge it so that we can reduce the conflicts.

  2. Collabration - Number of people can work on same projects by creating own branches so no one can interrupt their changes and merge their code once the project is ready.

    It supports workflows like feature branches, pull requests, and code reviews, which are essential for modern software development.

  3. Open Source tool - Git is open source, which means it’s free to use and has a large community of contributors who continuously improve it.

  4. Flexibility and Efficiency - Git is designed to be fast and efficient, handling large projects with ease. Operations like committing changes, branching, merging, and comparing versions are optimized for performance.

    It supports various workflows, from small individual projects to large, complex projects with thousands of contributors.

  5. Branching and Merging - Git’s branching model is one of its most powerful features. Developers can create new branches for different features, bug fixes, or experiments without affecting the main codebase.

    Merging - Branches can be merged back into the main codebase once they are ready, and Git provides powerful tools to resolve conflicts that may arise during merging.

  6. What is the difference between Main Branch and Master Branch?

    In Git 'main' and 'master' refers to the branches name. They served a same purpose act as a primary branches of the development works.

    1. 'master' - master is a traditional branch name for git tool. when we intialize a new repository in git by default the name of the branch is master.

    2. 'main' - In recent years, the GitHub platform has moved the 'main' as default branch name instead of master. This change was made to use more inclusive language, as "master" can be associated with negative connotations.

Functionality - There is no changes in both functionality. both name works as default primary branch in their own pace. You can choose your branches name by yourself as well, anything you want.

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

    Git -

    • Git is a distributed version control system (VCS) that tracks your changes in source code during software development.

    • It allows developers to manage and keep track of different versions of their code developement, and give option to collabrate their work efficiently.

    • Git is a command-line tool that can be used locally on a developer's machine.

Github -

  • GitHub is a web-based platform that hosts Git repositories online.

  • It provides a graphical interface for Git and adds several features, such as issue tracking, project management, pull requests, and more.

  • GitHub is a service that facilitates collaboration by allowing multiple developers to work on the same project from different locations.

Usage -

Git -

  • Git is used via command-line interface (CLI) or a GUI tool, and it’s where the actual version control happens.

  • Commands like git init, git add, git commit, git branch, and git merge are used to manage code locally.

Github -

  • GitHub is accessed through a web browser, GitHub Desktop, or GitHub CLI. Developers can also interact with GitHub using Git commands when pushing or pulling code to and from a GitHub repository.

  • GitHub provides a platform for sharing code with others, contributing to open-source projects, and managing collaborative development.

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

    1. Go to the new button to create a new repository on the GitHub.

  1. A new interface will be opened for creating a new repository in Github give the Repository name as per your choice and give description for more details of repository and click on create repository button at bottom right side.

Your new GitHub repository will be created by the name of Projects - DevOps projects.

  1. What is the difference between a local & remote repository? How to connect local to remote?

    Local Repository:

    • A local repository is a version of the Git repository that resides on your computer or local environment.

    • It contains all the files, branches, and commit history related to your project.

    • You interact directly with the local repository when you make changes, commit, or branch.

Remote Repository:

  • A remote repository is a version of the repository that is hosted on a remote server, often on platforms like GitHub, GitLab, or Bitbucket.

  • It acts as a central repository where multiple developers can push and pull changes.

  • The remote repository facilitates collaboration and serves as a backup for your code.

How to Connect a Local Repository to a Remote Repository

Create a Local Repository - Intialize a local repository in your local environment inside your git project folder.

     git init

Note - Do not do git init inside your home directory for best pratice.

Create a Remote Repository - On platforms like GitHub, GitLab, or Bitbucket, create a new repository. You’ll be provided with a remote repository URL, which is usually in the format by using SSH:

    git@github.com:username/repositoryname.git

Add the Remote Repository to Your Local Repository - Use the git remote add command to link your local repository to the remote repository.

    git remote add origin git@github.com:username/repositoryname.git

Push Local Changes to the Remote Repository - After adding the remote, you can push your local commits to the remote repository.

    git push origin main
  1. Tasks -

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

      Set Username -

       git config --global user.name "Vibhuti Jain"
      

      Set Gmail -

       git config --global user.gmail "vibhutijain@gmail.com"
      
    2. Create a repository named "DevOps" on GitHub.

    3. Connect your local repository to remote repository.

      Use the git remote add command to link your local repository to the remote repository.

       git remote add origin git@github.com:Vibhuti456/Devops-.git
      

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

       ubuntu@ip-172-31-19-250:~/git-tutorial/Devops$ mkdir Git 
       ubuntu@ip-172-31-19-250:~/git-tutorial/Devops$ touch Day02.txt 
       ubuntu@ip-172-31-19-250:~/git-tutorial/Devops$ echo "This is day 2 of learning git" > Day02.txt 
       ubuntu@ip-172-31-19-250:~/git-tutorial/Devops$ cat Day02.txt 
       This is day 2 of learning git
       ubuntu@ip-172-31-19-250:~/git-tutorial/Devops$
      
    5. Push your local commits to the repository on GitHub.

      As we can see by doing git status on repository is untracked in this folder. Let's make it tracked to commit the changes.

      For making it track first do git add to Git repository.

       git add Git/
      

      Then do commit your changes by using commit commands and make sure you do add some messages too your commit for reference.

       git commit -m "Day2 Changes"
      

      After doing commit do git status and you will get this kind of messages in your screen that means you committed your changes successfully. Now push your local changes to your github repository.

       git push origin master