Essential Git Commands For Day to Day Development You Should Know

Essential Git Commands For Day to Day Development You Should Know

Season's greetings, dear readers! In this article, we will look at the most important git commands for day-to-day development. Git is an important part of day-to-day programming (especially if you work in a team) and is widely used in the software industry, so understanding its commands and what they're used for is a must.

What is Git?

Git is a DevOps tool used for source code management. It is a version-control system for tracking changes in computer files and coordinating work on those files among multiple people. It is a free and open-source version control system used to handle small to very large projects efficiently.

What are Git Commands?

Git Commands are a distributed version control system used for tracking changes in any set of files.

Now that we understand Git and what a Git command is, let's go over some of the most useful Git commands.

  1. GIT INITIALIZE COMMAND

    This command is used to create a new git repository locally in the project root. This is usually the first command you run in a new project.

    git init

  2. GIT CLONE COMAND

    This command is used to get a copy of an existing Git repository into your local computer. This command is a common way for users to obtain a development copy and manage all operations from their local repository.

    git clone <repository url>

  3. GIT STATUS COMMAND

    This command is used to show the state of the working directory and the staging area. It shows the files that are not tracked by Git, which changes have been staged and which one haven’t.

    git status

  4. GIT ADD COMMAND

    When changes and updates are made to files in the working directory, the "git add" command is used to add all changes made in the working directory to the staging area. It tells git that the changes are to be included in the next commit.

    To add changes of a particular file

    git add <file-name>

    To add all changes

    git add .

  5. GIT COMMIT COMMAND

    This command simply saves all your changes initially added using the ‘ git add’ command to the local repository.

    git commit –m “commit message”

  6. GIT PUSH COMMAND

    This command transfers all your commits from your local repo to a remote repo. Here, all changes and commits done remains in the local repo until a ‘git push’ command is used to publish and upload the local changes to a remote repo.

    git push origin main

  7. GIT FETCH COMMAND

    This command does the opposite of the ‘git push’ command. While ‘git push’ pushes the local contents to the remote repository, the ‘git fetch’ command downloads content from a remote repository into your local repository and it does so without overwriting existing local code in the current branch.

    Fetch all branches from a repository

    git fetch <remote>

    Fetch a specific branch from a repository

    git fetch <remote> <branch>

  8. GIT MERGE COMMAND

    This command combines multiple sequences of commits into one joined history. The ’git merge’ command takes two commit pointers, looks for a common base commit between them, and then creates a new merge commit that combines the changes.

    git merge

  9. GIT PULL COMMAND

    This command is a shortcut to a two-step process: fetch, then merge. The ‘git pull’ command downloads the remote content and immediately executes ‘git merge’ and this overwrites existing local code in the current branch.

    git pull

  10. GIT BRANCH & GIT CHECKOUT COMMAND

    While the ‘git branch’ command is used to create a new branch, the ‘git checkout’ command is used to navigate between branches created by the ‘git branch’ command.

    Create a new branch

    git branch <branch-name>

    Checkout into a branch

    git checkout <branch-name>

And that concludes this article. The above are only a few of the many git commands available, but they are the ones I use the most in my daily programming. I hope this article has given you a better understanding of the most commonly used git commands.

Wishing y'all happy holidays and until my next article, love and light!

Thank you for reading.🤗✨

You can follow me on Twitter