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

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

Find the answers by your understanding (shouldn't be copied by the internet & use hand-made diagrams) of the below questions and Write a blog on it.

What is Git and why is it important?

  • Git is a version control system that helps you manage the versions of your code and files. It provides detailed records of modifications, creations, deletions, and timestamps for every change. Git should be known to all programmers because of its extensive tracking features.

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.

What is difference Between Main Branch and Master Branch?

  • In Git, the main branch and the master branch differ mainly in terms of language and naming practice, 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.

Key Takeaway:

The difference between main and master branches in Git is primarily about the branch name. While historically master was commonly used as the default branch name, main has gained traction as a more inclusive alternative.

Many repositories and platforms have transitioned from using "master" as the default branch name to "main" in recent years to foster a more inclusive environment, but the core functionality and purpose of these branches remain the same—they serve as the primary line of development in a Git repository.

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: Imagine it like a time machine for your code. It keeps track of every change you make, allowing 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 home or 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.

Simplified Comparison:

  • Git is the tool you use on your computer to track changes in your files.

  • GitHub is the website/platform where you can store your files and collaborate with others using Git.

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 Initialize this repository with a README if you want to start with a README file.

  • Choose Repository Options:

    • You can select additional options such as adding a .gitignore file or a license.
  • Create Repository: Click the green Create repository button.

Congratulations! You've created a new repository on GitHub.

Once created, GitHub will display instructions on how to push an existing repository from the command line or how to create a new repository from scratch on your local machine and push it to GitHub.

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

  • Local vs. Remote Repositories and Connecting Them

    Local Repository (On Your Computer):

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

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

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

    • Commits: Changes are committed locally.

    • Key Benefit: Enables offline work and experimentation.

Remote Repository (On a Remote Server, e.g., GitHub):

  • Location: Hosted on a remote server accessible over the internet.

  • Hosting Platforms: GitHub, GitLab, Bitbucket, etc., provide remote repositories.

  • Collaboration: Allows multiple contributors to access and contribute to the same codebase.

  • Syncing: Changes are pushed to and pulled from the remote.

  • Key Benefit: Facilitates teamwork and code sharing.

Connecting Local to Remote Repository:

  1. Create Remote: On the hosting platform (e.g., GitHub), create a new repository.

  2. Clone Remote: Copy the repository's URL.

    • In your terminal, navigate to your project's root directory.

    • Use git clone <repository_URL> to download the remote repository to your local machine.

  3. Link Local and Remote:

    • Use git remote add origin <repository_URL> to set up a connection named "origin."

    • This connection points to your remote repository.

  4. Push Local Changes:

    • After making changes locally, use git add . to stage changes.

    • Use git commit -m "Your commit message" to commit changes.

    • Finally, use git push origin main (or the appropriate branch name) to send changes to the remote.

  5. Pull Remote Changes:

    • To get updates from the remote, use git pull origin main.

    • This fetches and merges changes made by others.

  6. Congratulations!: Your local and remote repositories are now connected.

Remember, the remote repository acts as a central hub for collaboration, while your local repository lets you work offline and experiment before sharing changes. Regularly pushing and pulling updates helps keep both repositories in sync.

Task-1

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

  • To set your username and email address associated with your Git commits, you can use the following Git commands in your terminal or command prompt:

Setting Username:

git config --global user.name "Your Username"

Replace "Your Username" with your desired username.

Setting Email Address:

git config --global user.email "your_email@example.com"

Replace "your_email@example.com" with your actual email address.

Verify Settings:

You can verify if your username and email have been set correctly by using:

git config --global --get user.name
git config --global --get user.email

These commands will ensure that your commits are associated with the correct username and email address when you push changes to a Git repository.

Task-2

  • Create a repository named "Devops" on GitHub.

  • Connect your local repository to the repository on GitHub.
git clone https://github.com/nallabellisriparthu/Devops.git

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

echo "This is day2 file and added some content" > Day-02.txt

git add Day-02.txt && git commit -m "Added some story in Day-02"

  • Push your local commits to the repository on GitHub.
git push origin main

Note: In the place of password you need to past your Personal access token.

Note: These steps assume that you have already installed Git on your computer and have created a GitHub account. If you need help with these prerequisites, you can referday-8 blog


Happy Learning

Thanks For Reading! :)

-SriParthu💝💥