Git Vs GitHub
Gautam Kumar
Sr. Data Scientist | GenAI | LLM | RAG | Advanced Analytics | MLOps | Ericsson | Ex-HCL | Ex- Accenture l Machine learning | NLP | AI BOT I NEO4J | Deep Learning l GCP | AWS | Azure
What is Git?
Git is a distributed version control system (VCS) widely used in software development, allows multiple developers/coder to collaborate on a project by tracking and managing changes to source code files. Git maintains a complete history of changes made to the repository, making it easy for developers to keep track of changes to the codebase.
There are many other Version control software available in current market listed below:
Subversion (SVN)
Mercurial
Perforce
Bazaar
etc..
Features of Git:
Version control system:?Git provides version control features that allow developers/coder to track changes to files over time. Records all changes (both minor and major) made to the repository, including additions or deletions.
Distributed architecture:?Git is a distributed VCS(version control system), which means that each developer has a complete copy of the repository, including its entire history, on their local machine. This allows developers to work offline and independently, but still have access to the entire project history.
Branching and merging:?Git allows developers to create branches, which are separate lines of development. Branches are useful for working on new features or experimenting with code changes without affecting the main code base. Git also provides branch merge tools, so changes can be propagated from one branch to another.
Collaboration and remote repositories:?Git supports collaboration by providing the ability to connect to remote repositories. Developers can push their local changes to a remote server, allowing others to access and make changes to the same codebase. Popular remote repository hosting platforms such as GitHub, GitLab, and Bitbucket offer additional collaboration features on top of Git.
Commits:?In Git, the programmer creates commits to store a snapshot of your changes. Commits are accompanied by descriptive messages that explain the purpose and details of the changes. Commits serve as milestones in the project history, making it easier to navigate and understand how the codebase evolved.
Staging area:?Git has a staging area, also called an index, where developers can selectively choose which changes they want to include in the next commit. This allows for more granular control over commits and the ability to review and modify changes before finalizing them.
GitHub, on the other hand, is a web-based platform built on top of Git. It provides hosting services for Git repositories and adds additional features that make collaboration and project management easier. GitHub allows developers to store their Git repositories remotely, providing a central hub for code sharing, collaborating with others, and managing project-related tasks. It offers features like pull requests, issue tracking, code reviews, and integration with various development tools.
While Git is primarily a?command-line tool, GitHub offers a user-friendly web interface and integrates with Git to provide a more accessible and collaborative environment. Developers can use Git without GitHub, but GitHub relies on Git as its underlying version control system.
Difference between GitHub, Gitlab and Bitbucket
How to install Git and configure with GitHub ?
You can download the installer from the official Git website
“https://git-scm.com/downloads" and follow the installation instructions for your specific platform, Git provides installers for various operating systems, such as Windows, macOS, and Linux.
After installing Git, you need to configure your identity, which includes your name and email address. Open a git terminal or command prompt and run the following commands, replacing the placeholders with your actual name and email:
git config — global user.name “Your Name”
领英推荐
git config — global user.email “[email protected]”
Now we have two options, Create a new repository or Clone an existing one:
Create a new repository:?If you want to start with a new project, navigate to the desired directory in your terminal or command prompt and run?“git init”?. This initializes a new Git repository in the current directory.
Clone an existing repository:?If you want to work with an existing project, you can clone it from a remote repository. Go to the repository’s page on GitHub or any other Git hosting service, find the repository’s URL, and run?“git clone <repository URL>”?in your terminal or command prompt. This will create a local copy of the repository on your machine.
Now you have a repository set up, you can start working with Git by adding files, making changes, and committing them. Use commands like git add, git commit, and git status to manage your changes.
Git Basic Commands:
git init:?Initializes a new Git repository in the current directory.
git clone <repository>:?Creates a copy of a remote repository on your local machine.
git add <file>:?Adds a file or files to the staging area, preparing them to be committed.
git commit -m “message”:?Commits the changes in the staging area to the repository with a descriptive message.
git status:?Shows the current state of the repository, including modified, added, or deleted files.
git diff:?Displays the differences between the current code and the previous commit.
git pull:?Fetches and merges changes from a remote repository into your local branch.
git push:?Uploads your local commits to a remote repository.
git branch:?Lists all the branches in the repository.
git checkout <branch>:?Switches to the specified branch.
git merge <branch>:?Merges the changes from the specified branch into the current branch.
git log:?Displays the commit history of the repository.
git remote add <name> <url>:?Links your local repository with a remote repository.
git remote -v:?Shows the remote repositories associated with your local repository.
git rm <file>:?Removes a file from the repository and stages the deletion.
You can also use?git — help?or refer to the official Git documentation for more information on each command.