What is Git?
Git is a version control system for software development that allows multiple developers to collaborate on a project while keeping track of changes to the code. Git allows developers to create "branches" of a project, where they can work on different features or bug fixes without affecting the main codebase. Once changes are made, they can be merged back into the main branch or reviewed by other developers before being merged.
What is Github?
GitHub is a web-based platform that allows developers to host and collaborate on Git repositories. GitHub allows developers to store their Git repositories in the cloud, making it easy to access and collaborate on code from anywhere with an internet connection. Users can create repositories for their projects, track issues and bugs, and create pull requests for code review and collaboration.
Git and github are two steps required for devops, there are other remote repositories holder but major use is going on with github.
What is Version Control? How many types of version controls we have?
Version control is a software tool that allows developers to keep track of changes to their code over time. It is used to manage changes to source code, documentation, and other files that make up a software project.
Version control systems (VCS) enable developers to work together on code and track changes to the codebase over time. They provide features such as branching, merging, and versioning, which enable developers to work on different features or bug fixes without interfering with each other's work.
There are two main types of version control systems:
Centralized Version Control Systems (CVCS): In a CVCS, there is a single central server that holds the entire history of the codebase. Developers check out files from the central server to work on them, and then check them back in when they are done. Examples of CVCS include SVN (Subversion) and CVS (Concurrent Versions System).
Distributed Version Control Systems (DVCS): In a DVCS, each developer has a local copy of the entire repository on their machine, and changes can be made and committed locally without the need for a central server. Changes can be shared with other developers through push/pull operations. Examples of DVCS include Git and Mercurial.
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.
To install git:
For windows download file from https://git-scm.com/download/win
Download the exe file and install on system.
For MacOs -> You need homebrew for that run command in terminal as
$ brew install git
and after that type command to download and install git on local as$ sudo port install git
. Checkgit --version
it will verify that git is installedFor linux:
Debian/Ubuntu For the latest stable version for your release of Debian/Ubuntu # apt-get install git For Ubuntu, this PPA provides the latest stable upstream Git version # add-apt-repository ppa:git-core/ppa # apt update; apt install git Fedora # yum install git (up to Fedora 21) # dnf install git (Fedora 22 and later) Gentoo # emerge --ask --verbose dev-vcs/git Arch Linux # pacman -S git openSUSE # zypper install git Mageia # urpmi git Nix/NixOS # nix-env -i git FreeBSD # pkg install git Solaris 9/10/11 (OpenCSW) # pkgutil -i git Solaris 11 Express # pkg install developer/versioning/git OpenBSD # pkg_add git Alpine $ apk add git Red Hat Enterprise Linux, Oracle Linux, CentOS, Scientific Linux, et al. RHEL and derivatives typically ship older versions of git. You can download a tarball and build from source, or use a 3rd-party repository such as the IUS Community Project to obtain a more recent version of git. Slitaz $ tazpkg get-install git
Just check your linux os and copy the command and paste it.
Exercises:
Create a new repository on GitHub and clone it to your local machine
Make some changes to a file in the repository and commit them to the repository using Git
Push the changes back to the repository on GitHub
1) To create a new repo option is given on right hand corner that has + sign click on it and select new repo and fill the required details as name for the repo and select if you want private or public and click on create repository
2) Now to bring this repo on local open the repo and there is option as code click on it there are 3 options to bring that repo to local we are using https. In your terminal command git clone <github http url>
Inside the github url paste http url of code and enter. The local copy of the repo will be created Now you can perform any tasks.
3) Now after adding data on local we have to send that changes to remote to save it over there instead of local, so we need to run command git add .
This will add all the change of the folder on the staging area. Then git commit -m "Your message to display"
this will ensure the commit to staging are and mark it as ready to send to remote. Now type git push
this command will send all the changes to remote.