Table of contents
🦑What is Git and why is it important?
Git is a VCS(Version Control System) which provide an array of functionality through which working on project become breeze, It allows you to track changes to files and co-ordinate work on those file, Basically it is used for software development but we can use to track the changes to any set of files.
It provides flexible version control system, enabling efficient collaboration, easy code management, and the ability to track changes over time.
🦑What is difference Between Main Branch and Master Branch?
The main difference between the "main" branch and the "master" branch lies in their naming convention and historical context within version control systems like Git.
Master Branch: Historically, Git repositories typically used the term "master" for the primary branch that contains the latest stable version of the code. However, the term "master" has received criticism for its potentially negative naming convention, particularly its association with slavery and its lack of inclusivity.
Main Branch: In response to this, many communities, projects, and organizations have adopted the term "main" as an alternative to "master" for their primary branch. The "main" branch serves the same purpose as the "master" branch: it contains the latest stable version of the code and serves as the default branch for many operations.
In summarized way, the difference between the two is primarily semantic, with "main" being a more inclusive and neutral alternative to "master" in naming the primary branch of a repository. However, from a technical standpoint, they serve the same function within version control systems.
🦑Can you explain the difference between Git and GitHub?
Git and GitHub are related but serve different purposes in the context of version control and collaborative software development.
Git:
Git is a distributed version control system (DVCS) designed to handle everything from small to very large projects with speed and efficiency.
Allows developers to track changes in source code during software development. It enables multiple developers to work on the same project
without conflicting with each other's work. Users can create branches, make changes, merge branches, and revert to previous versions easily.
Key Features:
Distributed Version Control: Each developer has a complete copy of the repository on their local machine.
Branching and Merging: Git makes it easy to create and manage branches for different features or versions of the code, and later merge them back into the main branch.
Staging Area: Changes can be staged before committing, allowing for selective commits.
Commit History: Git maintains a detailed history of all changes made to the codebase.
GitHub:
GitHub is a web-based hosting service for Git repositories. providing a platform for developers to store, share, and collaborate on projects.
Hosting: GitHub hosts Git repositories in the cloud, allowing users to access their code from anywhere with an internet connection.
Collaboration: GitHub provides tools for collaboration such as issue tracking, pull requests, code review, and project management.
Community and Social Coding: GitHub fosters a community around open-source software development, enabling developers to contribute to projects and collaborate with others.
Documentation: GitHub allows users to create wikis and README files to document their projects.
Git is a version control system used for tracking changes in source code, while GitHub is a web-based platform built around Git, providing hosting, collaboration, and project management features for software development projects.
📂How do you create a new repository on GitHub?
Creating a new repository on Github need below steps to be followed.
Sign in to GitHub: 🚪💻 Go to github.com and sign in to your GitHub account.
Navigate to Your Repositories: 🧭📂 Once logged in, click on the "+" icon in the top right corner of the page, then select "New repository" from the dropdown menu.
Set Up Your New Repository:
Repository Name: 🏷️ Choose a name for your repository. This should be relevant to the project you're working on.
Description (Optional): 📝 Add a brief description to help others understand what your project is about.
Visibility: 👀 Choose whether your repository will be public (visible to everyone) or private (accessible only to you and collaborators you specify).
Initialize this repository with a README: 📋 If you want to create a README file for your repository, check this option. A README file is helpful for providing information about your project, such as how to use it or contribute to it.
Add .gitignore: 🚫 You can select a .gitignore file template to exclude certain files or directories from being tracked by Git.
Choose a License: 📜 You have the option to select a license for your repository. This determines how others can use, modify, and distribute your project.
Create Repository: 🚀🎉 Once you've filled in the necessary information, click the "Create repository" button.
That's it! You've successfully created a new repository on GitHub.
What is difference between local & remote repository? How to connect local to remote?
Local Repository: A local repository is the copy of your project that remain on your local machine. It contains all the files, commit history, and branches associated with your project. You work on this repository directly on your computer.
Remote Repository: A remote repository is hosted on a remote server, such as GitHub, GitLab, or Bitbucket. It serves as a central hub where multiple developers can collaborate on the same project. It's a shared version of your project that others can access and contribute to.
Connecting Local to Remote Repository:
To connect your local repository to a remote repository, typically hosted on platforms like GitHub, follow these steps:
Create a Remote Repository: First, create a repository on the remote platform (e.g., GitHub).
Locate the Remote Repository URL: On the remote platform, find the URL of the repository. You'll need this URL to connect your local repository to the remote one.
Initialize Git in Your Local Repository (if not done already): If you haven't already initialized Git in your local project directory, you can do so by running
git init
in your terminal/command prompt within the project directory.Add Remote Repository URL: Use the
git remote add
command to add the URL of the remote repository to your local repository. For example:git remote add origin <remote_repository_URL>
Replace <remote_repository_URL> with your remote repo's URL.
Verify Connection: To verify that the remote repository is correctly added, you can use the
git remote -v
command, which will show you the URLs of the remote repositories associated with your local repository.Push Your Changes to Remote: After connecting your local repository to the remote one, you can push your changes to the remote repository using the
git push
command. For example:git push -u origin main
This command pushes your changes from the
main
branch of your local repository to themain
branch of the remote repository.Once these steps are completed, your local repository will be connected to the remote repository.
🛠️Tasks:
Set your user name and email address, which will be associated with your commits.
git config --global user.name "Your Name" git config --global user.email "your.email@example.com"
Create a repository named "Devops" on GitHub.
Connect your local repository to the repository on GitHub.
git init # Initialize a new Git repository locally (if not initialized) git remote add origin https://github.com/your-username/Devops.git
Create a new file in Devops/Git/Day-02.txt & add some content to it.
mkdir -p Devops/Git echo "Hello!" > Devops/Git/Day-02.txt
git add . git commit -m "Add Day 02 content"
Push your local commits to the repository on GitHub.
git push -u origin master
⛔Conclusion:
By following a few steps, users can establish a centralized location for their DevOps-related projects, facilitating collaboration and efficient version control. This underscores the importance of leveraging tools like Git and platforms like GitHub to streamline development workflows and enhance project management in the context of DevOps methodologies.
😊Happy Learning:)