DEV Community

Cover image for Most Used Git Commands
Raj Kishor Shaw
Raj Kishor Shaw

Posted on • Updated on

Most Used Git Commands

I heard the term Git and GitHub a few months back when a discord community had organized an event for beginners in open-source. You just had to submit a meaningful pull request after taking a Good-first issue and solving the issue. I won a Swag T-shirt for changing some designs on the landing page of the Amplication website.

I wanted to learn about git commands for contributing to the above-mentioned event. I learned about some of the commands that programmer uses in their daily life for contributing to open source projects. I am adding some of the most used git commands that will help beginners in getting started in the open-source world.

  • $ git init
    It is used to create a new Git repository. It creates all the necessary files and directories for git to keep track of everything.
    It creates a file with the name .git and keep all the necessary file in it.

  • git config
    If you are first time using git, you need to configure it. This command allows you to specify the username and email address that will be used with your commits.

#### for setting up Git with your name
git config --global user.name "<Your-Full-Name>"

#### for setting up Git with your email
git config --global user.email "<your-email-address>"

  • git clone
    This command helps you to clone a remote repository to your GitHub and your local system. It downloads all the code related to that repository to your machine. You need to download all the codes of a working remote repository to your system for working with it.

  • git status
    This command helps you to check the status of your repository. It will tell you every information related to it. If you are a beginner using this command will help you a lot.

  • git diff
    This command helps you to check the difference between the working tree to the changes that you have made in your local file before saving the file.

  • git add
    This command helps you to move your file from the working directory to the staging index. This is a necessary step before committing your file to the remote repository.

  • git commit
    This command saves a log message along with the commit id of the modification you made to the git repository. You have to add a commit message in it describing the changes you made. This message will show up in your repository after opening a pull request.

$ git commit –m "<Type your commit message here>"

  • git push
    This command helps you to push the files of your local repository to the remote repository.

  • git branch
    This command helps you to add a new branch, list all the existing branches, and delete the branch.

  • git merge
    This command helps you to join your branch to the parent branch.

  • git pull
    This command is used to fetch and integrate the remote repository to your local repository. It helps you to be updated with the latest changes that have been made in the repository.

  • git log
    This command is used to show all
    repository commits that had been made in the past.

  1. cd — Returns you to your login directory.
  2. cd - — Returns you to your previous working directory.
  3. cd ~ — Also returns you to your login directory.
  4. cd / — Takes you to the entire system's root directory.
  5. cd /root — Takes you to the home directory of the root user.

Top comments (0)