This is all my knowledge that has been accumulated from a Udacity Course a few years back. Have you ever Heard of Git or Github or Gitlab, etc? And you want to know what in the world Git is? But not sure of the material you have read? Or is this the first article that you came across?
Don't Worry Cause this Blog Post will not only answer all these questions but also help you make your very first- "Git commit"
NOW what is that, Well Don't worry, Let's Start from Basics shall WE?
Git: Global Information Tracker Well that doesn't explain a lot, in fact this makes it even more complex. Let me Explain.
What is Version Control?
Have you ever heard of a Version Control System? No? Well, in layman's language Version control, also known as source control, is the practice of tracking and managing changes to software code. {credit: atlassian.com} Seems less confusing right?
So, there are three(3) Version Control Systems or VCs for short:
Git
Mercuria
Subversion
We here are talking about Git so, lets only stick to that for now. But before that, There are two(2) types of VCs
Centralized: All-powerful central computer that hosts the projects
Distributed:
A not central repository of info
- Meaning, Each developer has a complete copy of the project on their computer which means you can also work offline.
Guess what type of VC Git is? It's the Distributed Version Control System.
What is GitHub?
It is a service that hosts Git projects Basically, another computer where you can upload a copy of your project. And yes you guessed it right that means it's a Centralized System. Very TRUE.
Before we move further let's make some things clear:
What is a typical Centralized Versional Control Workflow(or CVC for short)?
Bug Fixing
Pull down any changes other people have made from a central server
Make your Changes and Commit them to the central server, so other programmers can see them as well.
Well, a Good NEWS for you, Because that's exactly how Github works and that's exactly what we need to do.
#Advantages of Distributed VC or DVC (for short) on CVC.
Performing actions other than pulling and pushing is extremely fast because tools only need access to the hard drive and not the remote server
Committing new changes can be done locally without anyone else seeing them
Everything can be done Offline (Except Pulling and Pushing).
Disadvantages of CVC on DVC:
If your project contains many large, binary files that cannot be easily compressed, the space needed to store all versions of these files can accumulate quickly
If your project has a very long history then downloading the entirety of that would take a lot of time.
Terminologies:
Pulling: The act of getting new changes from the repository.
Pushing: The act of moving your own changes to the repository.
Commenting: The act of recording(or pushing) the changes in the central system so that other programmers can see them.
Repository/Repo:
Making a Github Profile
Its very simple goto Github you will be treated by this page:
just enter your email in the Sign in Github tab follow through and
create a password and
verify your mail and THAT' ALL you have created your GitHub Profile
One thing I will recommend is
setting up your profile as you like
make sure to fill out your about me page
And, make a Your Name Readme. md file, Here is a list of tutorials for that Profile Readme This looks a lot more pleasing as a first impression.
Now that you have created a beautiful profile make sure to create an SSH key by going to
Settings-> in the access tab-> SSh and GPG key-> New SSH key and Follow through the steps.
This key will make you a password that you have to use when you clone some repositories from GitHub. It's like a security key for your Github Profile.
How to Install Git?
Installing Git is a straightforward process. Follow these steps to get started:
Windows: Download the installer from the official Git website and run it. Follow the prompts in the installer to complete the installation.
MacOS: Git comes pre-installed on macOS. However, you can also install it using a package manager like Homebrew by running
brew install git
in your terminal.Linux: You can install Git using your distribution's package manager. For example, on Ubuntu, you can run
sudo apt-get install git
.
Git Commands and Functions
1. git log
Function: Displays the commit history of a repository.
Usage:
git log
2. git show
Function: Displays the details of a specific commit.
Usage:
git show [commit hash]
3. Commit Message
Function: Provides a descriptive message for each commit, explaining the changes made.
Usage:
git commit -m "Your descriptive commit message"
Reset vs. Revert
Reset:
Function: Resets the current HEAD to a specified state.
Usage:
git reset [commit hash]
Revert:
Function: Creates a new commit that undoes the changes made in a previous commit.
Usage:
git revert [commit hash]
Miscellaneous
1. Creating a New Repository:
Function: Initializes a new Git repository in the current directory.
Usage:
git init
2. Cloning a Repository:
Function: Copies an existing Git repository to your local machine.
Usage:
git clone [repository URL]
3. Checking Status:
Function: Displays the current status of the repository, including modified files and untracked changes.
Usage:
git status
4. Creating Branches:
Function: Creates a new branch for parallel development.
Usage:
git branch [branch name]
5. Merging Branches:
Function: Combines the changes from one branch into another.
Usage:
git merge [branch name]
6. Pushing Changes to Remote:
Function: Uploads local repository content to a remote repository.
Usage:
git push [remote name] [branch name]
7. Pulling Changes from Remote:
Function: Downloads changes from a remote repository and integrates them into the current branch.
Usage:
git pull [remote name] [branch name]
With these commands and functions, you'll be well-equipped to navigate your Git repositories with ease and efficiency. Happy coding!
Wanna Learn a Language but Don't know where to begin from? What is the BEST Programming Language to Start with