Useful Basic Git Commands

When using Git, the following are the basic commands you should know.

git add Changes from the working directory are transferred to the staging area. This allows you to create a snapshot prior to committing it to the official history.
git branch This is your all-purpose branch administration command. Within a single repository, it allows you to build isolated development environments.
git checkout Git checkout may be used to explore existing branches as well as check out old commits and file revisions. It’s a way to work on a specific line of development when combined with standard Git commands.
git clean Untracked files are removed from the working directory. This is the logical counterpart to git reset, which only works on tracked files (usually).
git clone Creates a duplicate of a Git repository that already exists. Cloning is the most common method for getting a functioning copy of a central repository for developers.
git commit This command saves the staged snapshot to the project’s history. This specifies the basic workflow for all Git users when used with git add.
git commit –amend The —amend flag to git commit allows you to make changes to the most recent commit. When you neglect to stage a file or leave critical information out of the commit message, this is quite beneficial.
git config A simple way to configure your Git installation’s configuration parameters. You’ll almost never need to use this after installing Git on a fresh development machine.
git fetch Fetching retrieves a branch from another repository, as well as all of the commits and files connected with it. It does not, however, attempt to merge anything with your local repository. This allows you to review modifications before committing them to your project.
git init Creates a new Git repository from scratch. This is the first command you should learn if you wish to put a project under revision control.
git log Allows you to look back over a project’s prior revisions. For presenting committed snapshots, it offers a variety of formatting options.
git merge A strong approach to bring changes from different branches together. Git merge allows you to put the project history back together after forking it with git branch.
git pull The automated version of git fetch is pulling. It gets a branch from a remote repository and merges it into the current branch right away. This is Git’s version of svn update.
git push The opposite of fetching is pushing. It allows you to migrate a local branch to a different repository, making it easier to publish changes. This is similar to svn commit, but instead of sending a single changeset, it sends a series of commits.
git rebase Rebasing allows you to shift branches around, reducing the number of merging commits. The linear history that results is generally much easier to comprehend and study.
git rebase -i To start an interactive rebasing session, use the -i parameter. This gives you all of the benefits of a standard rebase, plus the ability to add, amend, or delete commits along the way.
git reflog Git uses a tool called reflog to keep track of updates to branch tips. This enables you to return to changesets that aren’t referenced by any branch or tag.
git remote An easy-to-use tool for managing distant connections. It allows you to utilize a more relevant shorthand instead of supplying the complete URL to get, pull, and push actions.
git reset Undoes changes to the working directory’s files. Changes that have not been pushed to a public repository can be cleaned up or fully removed by resetting.
git revert Uncommits a previously committed snapshot. Reverting is a secure and simple approach to totally delete a problematic commit from the code base when you discover it.
git status The current status of the working directory and the staged snapshot are displayed. To see exactly what’s being included in the next snapshot, use this in conjunction with git add and git commit.


Leave a Comment

Your email address will not be published. Required fields are marked *