Top 20 Most Used Git Commands

Top 20 Most Used Git Commands

1. git config

git config is used to set up the user configuration such as name, email, etc.

$ git config --global user.name "manish"
$ git config --global user.email maxmanishcosta.com

2. git init

This command is used to initialize the git repository for our local project folder.

git init

3. git clone

This command is used to obtain an already existing repository to your local system from a repository link.

git clone <repository-link>

4. git add

This command is used to add untracked changes to the repository which are ready to commit.

git add .

5. git commit

This command is used to store the current snapshot of files in the repository with a message assigned to it. git commit is the main command using which we can check the version history. All the files in the current directory are stored in the Git file system.

git commit -m "Add a Message"

6. git push

Git push allows us to transfer files from the local repository to remote repository hosting services like GitHub.

git push -u origin master

7. git tag

It will help the commits by giving them a particular tag, using which we can find the version of our project very easily.

git tag {tag name}

8. Git Branching

git branch

List all of the branches in your repository. This is synonymous with git branch --list.

git branch

Create a new branch called <branch>. This does not check out the new branch.

git branch <branch>

Delete the specified branch. This is a “safe” operation in that Git prevents you from deleting the branch if it has unmerged changes.

git branch -d <branch>

Rename the current branch to <branch>

git branch -m <branch>

This will merge the specified branch with our master branch.

git merge <branch name>

Switching to other Branches.

git checkout <branch name>

Making a new branch and directly switching to it

 git checkout -b <branch name>

8.Git clone from GitHub

git clone

git clone is used to clone the copied repo onto your local machine

git clone <copied URL>

To specify a specific folder to clone to, add the name of the folder after the repository URL

git clone <copied URL> <folder name>