What is Git & GitHub & why it is so Popular.?
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. It was initially developed by Linus Torvalds, the creator of the Linux operating system, in 2005. Git allows multiple developers to work on the same codebase simultaneously without disrupting each other's work, enabling efficient collaboration.
GitHub: GitHub is a website and cloud-based service that helps developers store and manage their code, as well as track and control changes to their code.
Git's popularity stems from several factors:
Distributed Version Control: Git is a distributed version control system, which means that every developer has a copy of the code repository. This makes it easy to work offline and synchronize changes when a connection is available. It also ensures that the codebase is not lost if the central repository is compromised.
Branching and Merging: Git allows developers to create branches, which are separate copies of the codebase that can be modified independently. This enables developers to work on different features simultaneously without disrupting each other's work. Git also makes it easy to merge changes from different branches back into the main codebase.
Open-Source Community: Git is open-source, which means that anyone can contribute to its development. This has led to a large and active community of developers who contribute to the project and develop tools and integrations to make Git even more powerful.
Integration with Other Tools: Git integrates with a wide range of tools and services, such as GitHub, GitLab, Bitbucket, and many others. This makes it easy to use Git in conjunction with other tools and services that developers use for coding, testing, and deployment.
Advantages:
Overall, Git's popularity can be attributed to its flexibility, speed, and efficiency, which make it an essential tool for developers working on projects of all sizes"
Advantages of Git:
Speed: Git is designed to be fast and efficient, which makes it ideal for large codebases and distributed teams.
Security: Git is secure by design, with built-in features for authentication, encryption, and access control.
Advantages of GitHub:
Collaboration: GitHub is a social coding platform that makes it easy for developers to collaborate on code, share ideas, and contribute to open-source projects.
Code review: GitHub provides tools for code review, including pull requests and code comments, which make it easy for developers to provide feedback on each other's code.
Issue tracking: GitHub provides a built-in issue-tracking system that makes it easy to track and manage bugs, feature requests, and other tasks related to the project.
Integrations: GitHub integrates with a wide range of tools and services, such as CI/CD tools, code editors, and project management tools, making it easy to incorporate GitHub into a development workflow.
Overall, Git and GitHub provide developers and organizations with powerful tools for version control, collaboration, and project management, which make it easier to develop high-quality software efficiently and securely."
Git Flow:
Working Directory:
The working directory is the directory on your local machine where you have cloned or initialized a git repository. it is the place where you can modify files and add new files or delete files in your current workspace.
Staging area:
The staging area, also known as the index, is a key concept in Git that allows you to control which changes you want to include in your next commit.
When you make changes to files in your working directory, Git sees these changes as modified files. To commit these changes, you need to first stage them by adding them to the staging area using the git add command. This tells Git that you want to include these changes in your next commit.
Once you have added the changes to the staging area, you can review them using the git diff --staged command. This shows you the differences between the files in the staging area and the last commit.
When you are ready to commit the changes, you use the command
git commit -m " commit message" command to create a new commit with the changes in the staging area. Git then moves the branch pointer to the new commit.
Remote Repository
In Git, a remote repository, or "remote repo" for short, is a repository that is hosted on a different machine or server than your local machine. It is a copy of the repository that you can access and interact with from your local machine.
When you clone a repository from a remote repo, Git creates a local copy of the entire repository, including all of its branches and commit history. You can then work with the repository locally, making changes, creating new branches, and committing changes to the local repository.
In this case, you can push your changes to the remote repository or pull changes from the remote repository to your local repository.
Git provides commands like git push and git pull to interact with remote repositories. git push sends your changes to the remote repository & and git pull retrieves changes from the remote repository and merges them into your local repository.
Remote repositories such as GitHub, GitLab, or Bitbucket, or can be self-hosted on a private server. They allow multiple people to collaborate on the same codebase, share changes, and work together more efficiently.
Git Commands.
$ git init
Initializes a new Git repository in the current directory.
$ git clone
Creates a copy of a remote Git repository on your local machine.
$ git add
Adds changes made to a file to the staging area. If a file has never been committed before, this command will also add it to the repository.
$ git commit
Creates a new commit with the changes in the staging area.
$ git push
Pushes the changes from your local repository to a remote repository.
$ git pull
Fetches changes from a remote repository and merges them with the local repository.
$ git branch
Lists all branches in the repository. An asterisk (*) indicates the current branch.
$ git checkout
Switches to a different branch.
$ git merge
Merges changes from another branch into the current branch.
$ git status
Shows the status of the working directory, including any changes that have been made but not yet committed.
$ git log
Shows a list of all commits made in the repository, along with their message, date, and author.
$ git log --oneline
The main purpose of this command is to print a single commit in a single line as output when the git log command is executed using this option.
$ git show commit id
Ex: git show 782e54543fbf55a137d34c9fe7bfa699b4347413
It will display the entire info about the commit
$ git diff
Shows the differences between the working directory and the last committed version.
$ git reset
Unstaged changes in the staging area.
$ git revert
Reverts a commit, creating a new commit that undoes the changes made by the original commit.
Git tags:
Git has the option to tag a commit in the repository history so that you can find It easier at a later point of time
Apply tag to a commit:
$ git tag -a <pattern> -m ‘comment’ <commit id>
Ex: git tag -a "R1.2" -m "commit for R1.2" aba89f4e25b45961985df052d136984fffc09c9e
Contents of the tag:
$ git show <pattern>
Display the list of tags available:
$ git tag
Creates a new tag to mark a specific point in the repository's history, such as a release.
$ git log --all --decorate --oneline --graph
this command will show the clear graph