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

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

  1. What is Git and why is it important?

-> Git is a version control system tool to maintain versions of code and files. It allows multiple developers to work on the same codebase simultaneously, it provides detailed records of creations, modifications, deletions, and timestamps for every change.

Key Features of Git:

  1. Version Control: Git keeps a complete history of changes made to files, allowing developers to revert to previous versions, track modifications, and understand who made specific changes.

  2. Branching and Merging: Git enables developers to create branches to work on specific features or fixes independently. These branches can be merged back into the main codebase, maintaining project integrity.

  3. Distributed Development: Git operates in a distributed manner, allowing each user to have a complete copy of the repository. This enables offline work and seamless collaboration across distributed teams.

  4. Security and Integrity: Each change made in Git is tracked using a unique hash, ensuring the integrity of the codebase. It also allows for authentication and access control to protect sensitive code.

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

-> In Git, the main branch and the master branch differ mainly in terms of language and branch name, with the latter encouraging more inclusive language.

Master Branch:

  • Historical Term:Master has been traditionally used as the default and primary branch name in Git for the main line of development.

Main Branch:

  • Inclusive Language:Main is an alternative term used to replace master in branch naming to promote more inclusive language in the tech community by avoiding potentially insensitive or exclusionary terms.
  1. Can you explain the difference between Git and GitHub?

  • Absolutely! Let's break it down in simple terms:

    Git:

    • What it is: Git is a type of software called a version control system.

    • What it does: It helps you manage and track changes to your files over time.

    • How it works: It keeps track of every change you make, and allows you to go back to previous versions if needed.

    • Key Point: It's like a tool you use on your computer to keep track of changes to your files, sort of like taking snapshots of your work along the way.

GitHub:

  • What it is: GitHub is a website/platform that uses Git.

  • What it does: It's like a hub where you can store your Git repositories (collections of files and their history).

  • How it works: You can upload your Git repositories to GitHub, making it easy to share your code with others, collaborate on projects, and keep a backup of your work in the cloud.

  • Key Point: GitHub is like a place in the cloud where you can store your code and collaborate with others. It's like a social network for developers, but instead of sharing photos or posts, you share and work on code together\

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

  • Sign in to GitHub: Open your web browser and go to GitHub. Sign in to your GitHub account.

  • Go to Your Profile: Click on your profile icon at the top right corner of the screen and select Your repositories from the dropdown menu.

  • Create a New Repository: On the Your repositories page, click the green New button on the right-hand side.

  • Fill in Repository Details:

    • Enter a name for your repository in the Repository name field.

    • Optionally, add a description to describe your project.

    • Choose between making the repository public or private.

    • Select Initializethisrepository with a README if you want to start with a README file.

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

  • Local vs. Remote Repositories and Connecting Them

    1. Local Repository: A local repository resides on your local machine. It's where Git stores all the files and metadata for your project.

    2. Remote Repository: A remote repository is hosted on a remote server (like GitHub, GitLab, or Bitbucket). It serves as a centralized location where your project can be stored and accessed by team members.

    3. Location: Exists on your local machine's storage.

    4. Version Control: Managed by Git, tracks changes to your code.

    5. Work Area: Where you edit, modify, and test your code.

    6. Commits: Changes are committed locally.

    7. Key Benefit: Enables offline work and experimentation.

  • A local repository resides on your local machine. It's where Git stores all the files and metadata for your project.

  • A remote repository is hosted on a remote server (like GitHub, GitLab, or Bitbucket). It serves as a centralized location where your project can be stored and accessed by team members.

  • Create a Remote Repository, follow previous step.

  • Initialize Git in your Local Repository,

linux$ git init
  • Add Remote Repository URL,
linux$ git remote add origin <remote_repository_url>
  • Push to Remote,
linux$ git push -u origin main

This command pushes the 'main' branch (or the branch you are currently on) to the 'origin' remote repository.

Tasks

Task 1:

  • Set your user name and email address, which will be associated with your commits.
git config --global user.name "Pooja Bhavani"
git config --global user.email "poojabhavani@gmail.com"

Task-2

  • Create a repository named "Devops" on GitHub.

  • Connect your local repository to the repository on GitHub.
ubuntu@ip-172-31-44-248:~git/DevOps$ git remote -v
origin https://github.com/pooja-bhavani/DevOp.git(fetch)
origin https://github.com:/pooja-bhavani/DevOps.git (push)
  • Create a new file in Devops/Git/Day-02.txt & add some content to it.
ubuntu@ip-172-31-44-248:~git/DevOps$ cat Git/Day12.txt
This is changes from local to remote repo
  • Push your local commits to the repository on GitHub.
git push origin main
ubuntu@ip-172-31-44-248:~git/DevOps$ git add Git/

ubuntu@ip-172-31-44-248:~git/DevOps$ git status
On branch master
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   Git/Day12.txt

ubuntu@ip-172-31-44-248:~git/DevOps$ git commit -m "Added New Content"
[master 7329b91] Added New Content
 1 file changed, 1 insertion(+)
 create mode 100644 Git/Day12.txt
ubuntu@ip-172-31-44-248:~/git/DevOps$ git push origin main
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 372 bytes | 186.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To github.com:pooja-bhavani/DevOps.git
   4bf5973..7329b91  main -> main