Introduction
Git is a powerful version control system that allows developers to manage and track changes in their codebase efficiently.
Its goals include speed, data integrity, and support for distributed, non-linear workflows (thousands of parallel branches running on different computers).From understanding commit history to managing branches and remote repositories.
Git is good
Git has the functionality, performance, security and flexibility that most teams and individual developers need. In side-by-side comparisons with most other alternatives, many teams find that Git is very favorable.
Features of Git ⚒️
• Tracks history
• Free and open source
• Supports non-linear development
• Creates backups
• Scalable
• Supports collaboration
• Branching is easier
• Distributed development
Commands in Git
Create Repositories
- git init
make Changes
add
commit
status
Parallel Development
branch
merge
rebase
Sync
push
pull
add origin
Version Control System (VCS)
What is version control? At a basic level, version control is the process of tracking and managing changes to files over time, and version control software helps automate this process. But that is only the beginning of what it does and why it’s important.
Version control is essential for development teams across all industries. It not only enables them to manage changes to code and files over time, but also allows them to work on the same project simultaneously. A good version control system allows for better collaboration and faster development, and it gives you a complete history of your digital assets.
Downloads
Click here for :- Windows
Click here for :- MacOs
Click here for :- Linux
GitHub 🐙🐾
Introduction
Development of the GitHub.com platform began on October 19, 2007. The site was launched in April 2008 by Tom Preston-Werner, Chris Wanstrath, P. J. Hyett and Scott Chacon after it had been available for a few months as a beta release.
GitHub is a for-profit company that offers a cloud-based Git repository hosting service. Essentially, it makes it a lot easier for individuals and teams to use Git for version control and collaboration.
Why GitHub so cool ?
Developers love using Github because GitHub repositories are essential They provide a platform to store and manage code, share projects with other people, collaborate on coding projects and much more, Also It makes collaboration so easy, and allows changes to be made by multiple people while keeping one source file.
Initializing a repository
To start using Git for version control in your project, you need to create a Git repository. This can be done using the git init
command. Navigate to your project's directory and execute the following .
git init
This command initializes an empty Git repository in the current directory. Once initialized, the directory will contain the necessary Git configuration and metadata to track changes in your project.
Making a Change
Once you've made changes to your project files, you can use Git to track and manage those changes. The process involves two main steps: staging and committing.
Staging :
To stage changes for commit, use the git add
command. This tells Git which changes you want to include in the next commit. For example:
git add example.txt # Stage a specific file
git add . # Stage all changes in the directory
Checking Status :
You can check the status of your changes using the git status
command. It provides information about which files are modified, staged, or untracked:
git status
Committing:
After staging your changes, you can commit them to the repository using the git commit command. This creates a snapshot of your changes with a corresponding message to describe the commit:
git commit -m "Added new feature"
View Commit History
To view the commit history of your repository, you can use the git log command. This provides a chronological list of commits, including commit messages, authors, dates, and commit hashes:
show previous commits
git log
To Remove from Staging Area :
git restore --staged [example.txt]
git-restore --staged
is about restoring files in the working tree from either the index or another commit.This command does not update your branch.The command can also be used to restore files in the index from another commit.
Reset a commit :
git reset [ # hash value of initial commit ]
Replace <commit_hash>
with the actual hash (or a unique prefix) of the commit you want to reset to. This command allows you to move the HEAD pointer and, optionally, the index (staging area) and working directory to the state of the specified commit. Keep in mind that there are different modes of git reset
Branches
In Git, a branch is a lightweight movable pointer that represents a specific commit in the version history of a repository. Branches allow you to work on different aspects of a project simultaneously, creating isolated environments where you can make changes without affecting the main codebase. This is especially useful for collaborative development, experimentation, and maintaining multiple versions of your code.
Each branch points to a specific commit, and as you make new commits on a branch, the pointer moves forward to the latest commit. This allows you to keep track of different lines of development, and later you can merge or rebase these branches to incorporate changes into the main branch (often called the "master" or "main" branch).
By default, when you initialize a Git repository, you start with a single branch called the "master" branch (or "main" branch in more recent terminology). However, you can create additional branches to work on features, bug fixes, or any other development tasks. Git makes it easy to switch between branches, create new ones, and manage the version history of your project.
List branches
git branch
List all branches (local + remote)
git branch -a
Create a new branch
git branch new-feature
Git Stash
The git stash
command is used to temporarily save changes that you've made in your working directory but don't want to commit yet. This can be useful when you need to switch to a different branch or pull in changes from another branch without committing your current changes. Here's a brief overview of how git stash
works:
git stash
Come again to untracked area
git stash pop
Conclusion
GitHub provides a platform for learning from others' code, reviewing code written by experienced developers, and collaborating on projects that align with your interests.
In essence, Git and GitHub have revolutionized the way software development is conducted, making version control and collaboration more accessible, efficient, and structured. Whether you're an individual developer, a team, or an open-source enthusiast, Git and GitHub offer powerful tools to enhance your coding experience and contribute to the broader developer community.
Keep Learning. . .🚀