Table of contents
- What is Git and why is it important?
- What is Github?
- Difference Between Main Branch and Master Branch:
- Difference between Git and GitHub:
- How to create a new repository on GitHub: To create a new repository on GitHub, follow these steps:
- Difference between local & remote repository and how to connect local to remote:
- What is Version Control? How many types of version controls we have?
- Why we use distributed version control over centralized version control?
- Tasks
What is Git and why is it important?
Git is a version control system used for tracking changes in files, particularly in the context of software development. It allows multiple developers to collaborate on projects simultaneously, tracking all modifications made to the source code.
Here's why Git is important:
History Tracking: Git maintains a detailed history of changes made to files over time. This allows developers to review past versions, understand how the code evolved, and revert back to previous states if needed.
Collaboration: Git facilitates collaboration among multiple developers working on the same project. It allows them to work independently on different features or branches and merge their changes seamlessly.
Branching and Merging: Git enables developers to create branches to work on new features or bug fixes without affecting the main codebase. Once the changes are complete, they can be merged back into the main branch, ensuring a smooth integration process.
Backup and Recovery: With Git, the entire project history is stored locally on each developer's machine as well as on remote repositories like GitHub or GitLab. This provides a backup in case of accidental deletions or system failures.
Code Review: Git supports code review workflows, where changes made by developers are reviewed by peers before being merged into the main codebase. This helps maintain code quality and ensures that only thoroughly reviewed changes are incorporated.
Open Source Contribution: Git has become the standard version control system for open source projects, facilitating contributions from developers worldwide. It lowers the barrier to entry for new contributors and fosters a vibrant community around the project.
Overall, Git streamlines the development process, enhances collaboration, and provides a robust framework for managing and tracking changes in software projects, making it an essential tool for modern software development workflows.
What is Github?
GitHub is a web-based platform that provides hosting for version control using Git. It is a subsidiary of Microsoft, and it offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its own features. GitHub is a very popular platform for developers to share and collaborate on projects, and it is also used for hosting open-source projects.
Difference Between Main Branch and Master Branch:
In Git, the term "master" branch was historically used as the default branch name. However, in recent years, there has been a shift towards using more inclusive language due to the racial connotations associated with the term "master." As a result, many projects and platforms, including Git itself, have adopted the term "main" instead of "master" to refer to the primary branch of a repository. Functionally, there is no difference between the "main" branch and the "master" branch; it's primarily a matter of terminology.
Difference between Git and GitHub:
Git is a version control system that allows developers to track changes to files, manage source code, and collaborate on projects.
GitHub is a web-based hosting service for Git repositories. It provides additional features on top of Git, such as issue tracking, pull requests, project management tools, and collaboration features. GitHub also facilitates social coding by allowing developers to share and discover open-source projects.
How to create a new repository on GitHub: To create a new repository on GitHub, follow these steps:
Log in to your GitHub account.
Click on the "+" icon in the top right corner and select "New repository."
Enter a name for your repository, add an optional description, choose whether it should be public or private, and select additional options if needed.
Click on the "Create repository" button.
Difference between local & remote repository and how to connect local to remote:
Local repository: A local repository is the copy of a Git repository that resides on your local machine. It contains the entire project history and all the files associated with the project.
Remote repository: A remote repository is a copy of a Git repository that resides on a server or a cloud-based hosting service like GitHub, GitLab, or Bitbucket. It serves as a centralized location for collaboration and backup.
To connect a local repository to a remote repository, you typically perform the following steps:
Initialize a new Git repository locally or clone an existing repository using
git init
orgit clone
respectively.Add a remote repository URL using
git remote add origin <remote_repository_URL>
.Push your local changes to the remote repository using
git push origin <branch_name>
.Pull changes from the remote repository to your local repository using
git pull origin <branch_name>
.
What is Version Control? How many types of version controls we have?
Version control is a system that tracks changes to a file or set of files over time so that you can recall specific versions later. It allows you to revert files back to a previous state, revert the entire project back to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.
There are two main types of version control systems: centralized version control systems and distributed version control systems.
A centralized version control system (CVCS) uses a central server to store all the versions of a project's files. Developers "check out" files from the central server, make changes, and then "check in" the updated files. Examples of CVCS include Subversion and Perforce.
A distributed version control system (DVCS) allows developers to "clone" an entire repository, including the entire version history of the project. This means that they have a complete local copy of the repository, including all branches and past versions. Developers can work independently and then later merge their changes back into the main repository. Examples of DVCS include Git, Mercurial, and Darcs.
Why we use distributed version control over centralized version control?
Better collaboration: In a DVCS, every developer has a full copy of the repository, including the entire history of all changes. This makes it easier for developers to work together, as they don't have to constantly communicate with a central server to commit their changes or to see the changes made by others.
Improved speed: Because developers have a local copy of the repository, they can commit their changes and perform other version control actions faster, as they don't have to communicate with a central server.
Greater flexibility: With a DVCS, developers can work offline and commit their changes later when they do have an internet connection. They can also choose to share their changes with only a subset of the team, rather than pushing all of their changes to a central server.
Enhanced security: In a DVCS, the repository history is stored on multiple servers and computers, which makes it more resistant to data loss. If the central server in a CVCS goes down or the repository becomes corrupted, it can be difficult to recover the lost data.
Overall, the decentralized nature of a DVCS allows for greater collaboration, flexibility, and security, making it a popular choice for many teams.
Tasks
Install Git on your computer (if it is not already installed). You can download it from the official website at https://git-scm.com/downloads
Create a free account on GitHub (if you don't already have one). You can sign up at https://github.com/
Task-1:
Set your user name and email address, which will be associated with your commits in the local repository.
Here, we can see we have set the username and email address in the local repository
Task-2:
Create a repository named "Devops" on GitHub
To create a new repostory in Github we have click on this icon , found on top right corner of Github, After that just click on the "New repository"
After that, you can see window like this in which you have set the repository name
Now, click on the create repository
Here, you can see a repository with the name "Devops" is added in the github
Connect your local repository to the repository on GitHub.
To connect your local repository to the Github repository, firstly we have to copy the github link of repository (Remote repository), which we want to copy on the local repository.
After that come to the local , come in the repository where you want Remote repository "Devops" to be added or cloned.
Note :-
We can connect our Local Repository to repository with several ways
For ex:-
Through HTTPS
Through SSH
Here, we have used HTTPS connection, here before doing git clone we have to set personal access token,after that we login with username and password for connecting our local repository to the Github. After that we can easily git clone our remote repository
Finally, we can see the repository that we have created on Github now it is also available in the local repository,
Create a new file in Devops/Git/Day-02.txt & add some content to it
Here, we have created Git Directory , inside it we have created a file "Day-02.txt"
Modify this file:
Push your local commits to the repository on GitHub
Now, to push our local commits to Github repository
We have to initially do a commit in our local
With command : git add <file-name> we are adding the untracked file in staging area and with git commit -m "statement" we are doing the local commit
Here, we have finally done a commit of file "Day-02.txt"
Now, to add our local commits to the remote repository we are git push origin , after that entering usernaame and password we are good to go,
Here, the commited is finally added to the remote repository
Once that done, on the Github we can see the locally created "Git" folder.
Also, the file inside it "Day-02.txt"
Inside this file we have written which we can also see on the remote repository