Day 9 Deep Dive in Git & GitHub
What is difference Between Main Branch and Master Branch?
The "master" branch and the "main" branch are terms used in version control systems, such as Git, to denote the primary branch of development. The meaning and usage of these terms have evolved over time.
Master Branch:
Historically, "master" has been the default and commonly used term for the primary branch in many version control systems, including Git.
The master branch often represents the main line of development, where the latest stable code is expected to reside.
Developers typically create feature branches, make changes, and then merge them back into the master branch once the features are complete and tested.
Main Branch:
In response to concerns about inclusivity and neutrality, some projects and organizations have adopted the term "main" instead of "master" for their primary branch.
The main branch serves the same purpose as the master branch: it represents the main line of development and is usually the default branch for most operations.
The switch from "master" to "main" is a conscious effort to use more inclusive language and avoid any potential associations with negative historical connotations.
It's important to note that both terms are essentially interchangeable in their function and purpose; the choice between them often depends on the preferences and policies of the project or organization using the version control system. As of my knowledge cutoff in January 2022, there's a trend toward adopting "main" as a default, but some projects may still use "master." Always check the specific documentation or conventions of the project or organization you are working with to determine which term they prefer.
What is difference between local & remote repository?
Local Repository:
A local repository is the copy of your project that is stored on your local machine.
It contains all the files, commit history, and branches related to your project.
Developers work with the local repository by making changes, creating branches, and committing their work.
Remote Repository:
A remote repository is a version of your project that is hosted on a server or another location separate from your local machine.
It serves as a centralized or shared repository where multiple developers can collaborate on the same project.
Remote repositories are often hosted on platforms like GitHub, GitLab, Bitbucket, or others.
Developers can push their changes from their local repository to the remote repository, and pull changes made by others from the remote repository to their local copy.
In summary, the main difference lies in the location and scope of the repository:
Local Repository: Stored on your local machine, contains the entire project, and is where you do your development work.
Remote Repository: Stored on a server or a centralized location, facilitates collaboration by allowing multiple developers to share and contribute to the project.
How to connect local to remote?
Connecting a local repository to a remote repository typically involves a few key steps. Here's a general guide using Git as an example:
Initialize a Local Repository: If you haven't already, initialize a Git repository on your local machine. Navigate to your project's directory in the command line and run:
git init
Create a Remote Repository: Create a remote repository on a hosting platform like GitHub, GitLab, or Bitbucket. Follow the platform's instructions to create a new repository.
Link the Local Repository to the Remote Repository: Once the remote repository is created, you need to link it to your local repository. Use the following command, replacing
<remote-url>
with the actual URL of your remote repository:git remote add origin <remote-url>
For example, if your remote repository is on GitHub:
git remote add origin https://github.com/your-username/your-repository.git
Verify the Connection: You can verify that your local repository is connected to the remote repository using:
git remote -v
This should display the fetch and push URLs for the remote repository.
Push Local Changes to Remote: After making changes in your local repository, you can push those changes to the remote repository using:
git push -u origin master
This command pushes changes from your local "master" branch to the remote repository. If you are using a branch other than "master," replace it with the appropriate branch name.
Tasks:-
1. Set your user name and email address, which will be associated with your commits.
1.To set the name and email commend will be used:-
(A) git config --global user.name "Your Name"
(B) git config --global user.email "Your Email"
2.Verify Your Configuration: You can check your configured user name and email using:
2.Create a repository named "Devops" on GitHub
Go to Your GitHub Dashboard: Once signed in, go to your GitHub dashboard by clicking on your profile picture in the top right corner and selecting "Your repositories" from the dropdown menu.
Create a New Repository: On the "Your repositories" page, click the "New" button.
Fill in Repository Information:
Enter "Devops" as the Repository name.
You can add a description, choose visibility settings, and initialize with a README file if you wish.
Click the "Create repository" button.