#Day9:- 90 Days DevOps Challenge@Deep Dive in Git & GitHub for DevOps Engineers.

#Day9:- 90 Days DevOps Challenge@Deep Dive in Git & GitHub for DevOps Engineers.

Mastering Git & GitHub for DevOps Excellence

🥏What is Git and why is it important?

🥨Git is a distributed version control system designed to track changes in source code during software development. It allows multiple developers to work collaboratively on a project, keeping a history of changes and facilitating seamless code integration. Created by Linus Torvalds in 2005, Git has become the industry standard for version control due to its efficiency, speed, and robustness.

The importance of Git in DevOps cannot be overstated for several reasons:

  1. 💥Version Control: Git enables precise tracking of changes made to source code over time. It provides a complete history of commits, allowing developers to review and revert changes if needed, which is crucial for maintaining code stability and reliability.

  2. 👨‍💻Collaboration: Git supports concurrent development by multiple developers on the same codebase. Through branching and merging, different team members can work on separate features or fixes and later integrate their changes smoothly into the main codebase.

  3. 👨‍💻Code Reviews: Git's branching and pull request features facilitate efficient code reviews. This process allows team members to assess proposed changes, provide feedback, and ensure code quality before merging into the main branch.

  4. 🕊️Continuous Integration and Continuous Delivery (CI/CD): Git integrates seamlessly with CI/CD pipelines. By automatically triggering build and deployment processes upon code changes, it enables rapid and reliable delivery of software to production environments.

  5. 🛡️Error Recovery: With Git's distributed nature, every developer has a complete local copy of the repository. This redundancy ensures that even in the event of server failures or data loss, code can be restored from any developer's local copy.

  6. ⛓️Branching Strategies: Git offers various branching strategies (like Gitflow, GitHub Flow, and GitLab Flow) that align with different development workflows. These strategies aid in organizing code changes, feature releases, and hotfixes effectively.

  7. 📝Open Source Ecosystem: Git is open-source, making it accessible to developers worldwide and fostering a vibrant community of contributors. This leads to continuous improvement, frequent updates, and the availability of numerous tools and integrations.

🥏What is the difference Between Main Branch and Master Branch?😕

The terms “main branch” and “master branch” refer to the default branch in a Git repository. The difference between these terms lies mainly in their naming conventions and historical context:

1️⃣Master Branch

  • Historically, “master” was the default branch name used in Git repositories for many years. It originated from the original version control system called BitKeeper.

  • The “master” branch typically represents the main development branch, where the latest changes and features are integrated before being released or merged into other branches.

  • However, the use of “master” has been recognized as carrying connotations of slavery and oppression, leading to a movement to replace it with more inclusive terminology.

2️⃣Main Branch

  • In response to the concerns raised about the term “master”, many Git hosting platforms and communities have moved towards adopting more inclusive naming conventions.

  • main” is a commonly used alternative to “master” as the default branch name. It aims to promote diversity and inclusion within the software development community.

The “main” branch serves the same purpose as the “master” branch, representing the primary branch for development, integration, and the latest changes.

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

🏠 Local Repository: A copy of the project on your computer where you make changes and commits.. ➡️ 👩‍💻

📡 Remote Repository: ➡️ 🌐A centralized online location (e.g., on GitHub) where you store and share your project with others.

Connecting Local to Remote:

  1. Create Remote Repository on 🌐 (e.g., GitHub).

  2. Get Remote Repository URL 🌐.

  3. Link-Local to Remote: git remote add origin <remote_repo_url> 🔄.

  4. Push Local Changes: git push -u origin <branch> 🚀.

  5. Pull Remote Changes: git pull origin <branch> 🔃.

Now you can collaborate and synchronize your work with others! 👥💻

TASKS 1:

😕How to set your user name and email address, which will be associated with your commits?

👨‍💻SOLUTION:- To set your user name and email address associated with your commits in Git, you can use the following commands:

  1. Set your user name:
git config --global user.name "Your Name"

Replace "Your Name" with your actual name.

  1. Set your email address:
git config --global user.email "your.email@example.com"

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

The --global flag makes these configurations apply globally to all repositories on your computer. If you want to set different user names and email addresses for specific repositories, you can omit the --global flag and run the commands inside the specific repository.

TASKS 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

📝SOLUTION:-🤳

Go to your GitHub account (If you don't have a GitHub account then, You can sign up at https://github.com/

:- Click On New (Right side green button) and create a new repository, Please refer to the below image:

:- Now enter your repository details to create a repository.

😃Now your repository is created successfully🎗️.

Click On the upper left side of your repository to see your all repositories.

🚀 In the next step, we will clone this repository into our local machine. 🖥️💻

:- Open Your Git ( if git is not installed on your pc then, You can download it from the official website at https://git-scm.com/downloads).

Now go to your Git Hub and click on your repository and copy the git repository URL.

In the next step, you are ready to clone your GitHub repo into your local machine.

🏃‍♂️Run the following command:-
git clone <your repository url>

📝NOTE:- Please put your repository address in place of "your repository url".

👨‍💻Now you can check the above image I have executed the git clone command and the respective repository copied into my local machine (In my case repo name is:- devops90days).

📝Make some changes to a file locally and commit them to the repository using Git.

:- Currently, our repository is empty. Please go to your local machine and make 1-2 changes by creating files in the respective directory.

:- Now type the below commands,

👨‍💻👨‍💻👨‍💻Link-Local to Remote:

  • In your local repository's terminal or command prompt, use the following Git command to link your local repository to the remote repository:

      git remote add origin <remote_repository_url>
    

    Stage the Changes: Use the git add . command to stage the changes you want to commit. For example, if you modified a file called "example.txt".

Commit the Changes: Committing records the changes you made to the file in the Git history. Use the git commit -m "Your commit message"command with a commit message describing the changes.

Push Changes to the Repository: If you cloned a remote repository and want to update the remote repository with your changes, you'll need to use the git push - u origin main (here, main is your branch name)command.

NOTE:- During the push command, it prompts for the password so login via the same GitHub credential.

🥏Conclusion

Git is a version control system crucial for tracking code changes and fostering developer collaboration. The distinction between "Main branch" and "Master branch" lies primarily in terminology, both referring to the default branch. While Git manages code changes, GitHub serves as a web-based hosting service for repositories, enhancing collaboration. To create a new GitHub repository, click the "+" sign, select "New repository," provide details, and create it. Local repositories enable independent work, while remote repositories (e.g., GitHub) encourage teamwork. Connecting them involves commands like "git remote add origin" and "git push."