Do you know this person named Linus Torvalds? He has created something truly remarkable, a game-changer for anyone navigating the vast world of the internet or wielding a device in their hands – the likelihood of it running on Linux is incredibly high.
He has also created Git.
Git, short for Version Control System (VCS), is a traditional system for managing versions.
Now, let's delve into the realm of Git learning. This article will guide you through the path of understanding Git, progressing from the basics to daily usage, providing you with the knowledge needed to kickstart your journey. Here's a brief overview: What is Git -> Git Basics -> Git Daily Uses (Essential Know-How to Get Started) -> Git It (Practical Tasks).
Towards the end, I'll share links to valuable tools and blogs that served as my references when I embarked on my Git journey.
What is Git
Picture this scenario: numerous developers altering the source code of software, each making their changes. Coordinating these changes becomes an arduous task for the maintainer trying to compile a final release version. In the past, code maintenance involved manual labor, creating new directories, and merging them by hand. Each project had a master copy inaccessible to others.
VCS simplified this process. Whether using Git or another VCS, the concept remains. In Git, every directory copy is a branch, and new branches can merge seamlessly. Changes are documented with commit messages, allowing contributors to explain their modifications. Git can identify breaking changes automatically.
Enough detail for the "What is Git" section; let's move on.
Git Basics
A repository, akin to a file folder, denotes a project in the Git system.
Creating a new repository:
git init
Branch
A branch is a working copy of the repository within the repository itself.
Creating a new branch from another:
git checkout -b feature master
Remote
Remote is the cloud location where your repository can be stored.
Clone a repository from remote:
git clone username@host:/path/to/repository
Staging Area
The Staging Area is where changes are prepared before committing to a branch.
Adding changes to the Index: (dot means all changes)
git add <filenames> or git add .
Commit
Committing involves adding changes to a branch.
Committing changes:
git commit -m "commit message"
Now, your changes are in the head but not yet in the remote repository.
Pushing Changes to Remote
Push your changes to a remote server.
Adding a remote:
git remote add origin <server>
Pushing changes to the remote:
git push <origin-name> <branch to push>
Pulling Remote Changes to Your Local Repository
Pull changes from other developers.
Pull changes to the current branch:
git pull
Merge another branch:
git merge <branch>
Git Daily Use Cases
For daily use, familiarize yourself with essential Git commands. The most common tasks involve adding a remote, pulling changes, making local changes, staging them, committing to the head, and pushing them to the server.
Superfast Commands Revision
Quick recap of superfast commands:
git remote add origin <remote-url>
git checkout <branch> (checkout to the required branch)
git checkout -b <branch-name> <source-branch>
git add . (add all local changes)
git commit -m "commit message" (add changes to HEAD)
git push origin <branch-name>
Final Thoughts
In conclusion, don't shy away from experimentation. Humans often struggle with memorization, and the same holds true for any profession or technology. When starting with Git, it may seem daunting, but like any challenge, take the plunge. Google is your friend; don't attempt to consume all content at once. Instead, focus on doing and practicing – a valuable lesson in our field.
Remember, doing is everything. -Unknown