Popular GIT commands
1. git init
2. git clone
3. git branch
4. git checkout
5. git add
6. git commit
7. git push
8. git pull
9. git merge
10. git status
Here we will explain only few, as others are explained in earlier pages:
git clone:
To make a local copy of an existing Git repository, use the git clone command. You can use it to retrieve all of the repository's files, branches, commit history, and other metadata. When you want to start working on a project or collaborate with others on an existing repository, this is really helpful.
The git clone command's fundamental syntax is as follows:
git clone <repository_url> [<destination_directory>] git clone https://github.com/arjun2010-ece/sample_repo.git
Repository URL: The
Destination Directory: The optional
git branch:
This command displays all the local git branch (please observe only local branch in your system not of remote or any other developers local branches). It is written like this::
git branch
git checkout:
This command is of 2 types and has 2 different purposes.
It is written like this::
// First way: create and move to a new branch git checkout -b feature/creating_navbar //Second way: Move to a new branch git checkout main
The first way of writing command is like this git checkout -b, here -b means create a new branch from current branch (mostly develop/main) with the given name of branch i.e. here feature/creating_navbar and then change this as the current branch, where you could write your code.
The second way is simply switching to any branch from any other branch.
git pull:
The purpose of this command is to pull latest commit or changes from any remote branch to any local branch.
If we are on a branch feature/creating_navbar currently and we fire git pull origin main, then we are pulling latest commits from main branch and thus refreshes our branch thus trying to avoid any conflict. And if any comes then we fix that locally.
Just remember that before doing git push command then this command is mandatory for every developer.
Just remember that this command is equivalent to git fetch + git merge.
git merge:
If we are on branch A locally and then want to merge branch B into branch A then simply run this command like::
git merge branchB // it will merge commits of branchB into branchA
git fetch:
The purpose of git fetch is to bring all the remote branches into our local system.
Then we can fire the command "git checkout feature/creating_navbar" to switch to that branch (which was not there locally before) and can run that locally or read the code too.
git fetch // bring all the branches from remote git checkout feature/creating_navbar // switch to that remote branch
git status:
The purpose of this command is to show the status on the current branch. If after firing, the terminal shows files in red color means we have not fired "git add ." command yet. If it shows
files in green color means we have not fired "git commit -m" command yet. It is extrememly useful command.
git status