Table of contents
- Introduction
- What is Git and why is it important?
- What is difference Between Main Branch and Master Branch?
- Can you explain the difference between Git and GitHub?
- How do you create a new repository on GitHub?
- What is difference between local & remote repository? How to connect local to remote?
- Connect your local repository to the repository on GitHub
- TASK :
- Conclusion
Introduction
In the world of software development and DevOps, efficient collaboration and version control are paramount. This is where Git and GitHub come into play. In this blog, we'll take a comprehensive look at these tools, from their basics to their crucial roles in modern software development.
What is Git and why is it important?
Git is a distributed version control system. Think of it as a smart time machine for your code. It tracks changes to your codebase over time, allowing you to revisit previous versions, collaborate seamlessly, and merge different contributions into a coherent final product. Git is essential for maintaining code integrity and streamlining team collaboration.
What is difference Between Main Branch and Master Branch?
In the past, the term "master" was commonly used as the default branch name in Git repositories. However, due to its potentially exclusionary connotations, many projects and platforms, including GitHub, have transitioned to using "main" as the default branch name instead. Essentially, the difference is in the name and its implications; the main or master branch serves as the default base for development.
Can you explain the difference between Git and GitHub?
Git is software and GitHub is a service. They are often used interchangeably, but they serve distinct roles. Git is the version control system itself, while GitHub is a web-based platform that provides a user-friendly interface for hosting Git repositories. GitHub extends Git's capabilities by offering collaboration tools, issue tracking, and more.
How do you create a new repository on GitHub?
Setting up a new repository on GitHub is a breeze:
Log in: Sign in to your GitHub account.
Click New: Click the '+' sign in the upper right corner and select "New Repository".
Name Your Repo: Give your repository a meaningful name.
Description (Optional): Add a brief description to explain the repository's purpose.
Public or Private: Choose whether you want the repository to be public (visible to everyone) or private (accessible to collaborators only).
README: Opt to initialize the repository with a README file. It's a great place to introduce your project.
Add .gitignore: Select a template to automatically ignore certain files (e.g., temporary files) from being tracked.
Choose a License: Pick an open-source license to define how others can use your code.
Create Repository: Click the "Create repository" button.
Your new GitHub repository is now ready for action!
What is difference between local & remote repository? How to connect local to remote?
Local Repository: This is the version of your project that resides on your local machine. It's where you do most of your coding and testing. A local repository is stored on your computer's hard drive. When you clone a repository from a remote server (e.g., GitHub, GitLab, Bitbucket) to your computer, you create a local copy of that repository on your machine. The local repository contains the "working directory," which is the current state of the project where you can modify files, add new files, and make changes to the code.
Remote Repository (GitHub): The remote repository is hosted on GitHub's servers. It is located outside of your local computer and accessible over the Internet. It's a way to store a backup copy of your code and collaborate with others. Your local repository can sync with the remote repository, allowing you to share changes and collaborate effectively. Even if a developer loses their local copy, the code and its history are still available on the remote server.
Connect your local repository to the repository on GitHub
Here's how to link your local repository to a remote repository on GitHub:
Copy Remote URL: On GitHub, go to your repository and click the green "Code" button. Copy the repository URL.
git init: Initializes that folder as git by creating .git folder.
Terminal: In your local repository's terminal, use the command
git remote add origin <repository-url>
to connect to the remote repository.Verify local and remote repositories connection by executing the command: git remote -v
Push to Remote: After making changes locally, use
git push origin main
(orgit push origin master
depending on branch names) to send your changes to the remote repository.And that's it! Your local and remote repositories are now connected.
TASK :
Set your user name and email address, which will be associated with your commits.
Create a new file in Devops/Git/Day-02.txt & add some content to it
created " Devops/Git/Day-02.txt"
Use
git add <file>
to tracked the file.commit the changes
Push your local commits to the repository on GitHub
You can push your local repository's code to the remote repository using the following command:
git push origin master
Conclusion
Git and GitHub are dynamic tools that empower DevOps engineers and software developers to work efficiently, collaborate seamlessly, and keep track of their codebase's evolution. Whether you're a solo coder or part of a global team, mastering these tools is a valuable asset in today's fast-paced development landscape.