Git is a distributed version-control system for tracking changes in any set of files, originally designed for coordinating work among programmers cooperating on source code during software development. Its goals include speed, data integrity, and support for distributed, non-linear workflows
GitHub is where over 56 million developers shape the future of software, together. Contribute to the open source community, manage your Git repositories, review code like a pro, track bugs and features, power your CI/CD and DevOps workflows, and secure code before you commit it.
BitBucket, GitLab are also similar to GitHub but GitHub is more popular.
In simple words, GitHub is like a storage bucket for your code(projects) whereas Git is used as an interactive tool between your local pc/folders and GitHub.
Git & GitHub together form the Version Control System.
A GIT Project consists of three major sections:
This command simply initializes a working directory for your
project as a git repository. Make sure you are in the
project directory and type the following command to
initialize a new repository.
Ex: git init
This command puts the desired file to the staging area for
operations to be performed on it.
Ex: git add index.html
To add all the
files to staging area: git add .
This command records the changes made to the git repository
by saving a log message together with a commit id.
Ex: git commit -m "First commit"
This command is used to see the status of working tree. It
shows the list of unstaged files and list of staged files
that needs to be committed to GitHub. If there is nothing to
be committed then it will simply show that the branch is
clean.
Ex: git status
First of all, you should create a new repository in your
GitHub account and give it a name of your choice. Head over
to this link
to create a new repo.
This commands adds the destination repo that your local
project repository(directory) must target to i.e. it
connects local to remote repository.
Ex:
git remote add origin
https://github.com/username/repoName.git
It creates a new branch of your repo. You can create
multiple branches for your repo also.
Ex:
git branch branch-1
By default you will be using the branch 'main' or 'master'.
This command sends all your local commits to the remote repo
i.e. the repo which you have newly created on GitHub. Hence
in this way, GitHub will act as a storage bucket.
Ex:
git push origin master
(or)
git push origin branch-1
This command creates a local working copy of an existing
remote repository. It simply clones to copy and downloads
the repository to your computer.
Ex:
git clone https://github.com/facebook/react
If by mistake, you had pushed a file which was not suppose
to be then this command is useful. We can delete the file
from the project(on your remote repo) and stage the removal
for commit.
Ex:
git rm secretkey.js
This command is used to revert the changes back to any of
the previous version of your project.
Be careful with this command and never ever accidently hit this because it might cause your app to crash even if it was working fine previously.
Ex:
git revert 6eb8701365c820330a6e4615cefb4ff4b75c390c
That's it from this blog post. If you liked it then do share this blog with your friends or people who wanna get into programming world. Thank You!