When it comes to popular text editors for Linux, text editors are like wallets. Everybody’s got one and more importantly, everyone’s choice of a text
In this article, we will review the top 10 most commonly used Git commands. You can’t call yourself a competent DevOps Engineer or IT professional for that matter, without a good working knowledge of Git and what it’s used for. It is a free and open-source version control system (VCS) used by collaborative projects in the software development world.
Image by ThisisEngineering from Pexels
git init
: Initializes a new Git repository in the current directory.
git init my-repo
: Initializes a new Git repository in a directory named “my-repo”.
git init --bare my-repo.git
: Initializes a new bare Git repository in a directory named “my-repo.git”.
git init --template=my-template
: Initializes a new Git repository using a custom template.
git clone
: Creates a local copy of a remote Git repository.
git clone https://github.com/myuser/my-repo.git
: Clones a repository hosted on GitHub.
git clone git@bitbucket.org:myuser/my-repo.git
: Clones a repository hosted on Bitbucket.
git clone https://my-git-server.com/myuser/my-repo.git
: Clones a repository hosted on a private Git server.
git add
: Adds changes to the staging area.
git add file1.txt
: Adds a single file to the staging area.
git add *.txt
: Adds all files with a “.txt” extension to the staging area.
git add -p
: Interactively add changes to the staging area.
git commit
: Records changes to the repository.
git commit -m "Initial commit"
: Commits changes with a commit message.
git commit -a
: Commits all changes in tracked files.
git commit --amend
: Amends the previous commit.
git status
: Shows the current status of the repository.
git status
: Shows the status of the repository.
git status -s
: Shows a shorter, more concise status output.
git status --ignored
: Shows ignored files in the status output.
git log
: Shows the commit history of the repository.
git log
: Shows the full commit history.
git log --oneline
: Shows a condensed commit history.
git log --author="John Doe"
: Shows the commit history of a specific author.
git branch
: Lists, creates, or deletes branches.
git branch
: Lists all branches in the repository.
git branch my-branch
: Creates a new branch named “my-branch”.
git branch -d my-branch
: Deletes the branch named “my-branch”.
git merge
: Merges changes from one branch into another.
git merge my-branch
: Merges changes from “my-branch” into the current branch.
git merge --no-ff my-branch
: Forces a new merge commit, even if a fast-forward merge is possible.
git merge --abort
: Aborts a merge that is in progress.
git remote
: Shows or manages remote repositories.
git remote
: Shows the names of all remote repositories.
git remote add origin https://github.com/myuser/my-repo.git
: Adds a new remote named “origin”.
git remote remove origin
: Removes the remote named “origin”.
git push
: Pushes changes to a remote repository.
git push origin master
: Pushes changes to the “master” branch on the “origin” remote.
git push --tags
: Pushes all tags to the remote repository.
git push --delete origin my-branch
: Deletes the “my-branch” branch on the “origin” remote.
Now that we’ve reviewed the top 10 commonly used git commands, let’s rank them in order of significance or more specifically, by frequency of use and importance in day-to-day Git workflows.
git init
: This command is used to initialize a new Git repository in the current directory. It is typically used only once when starting a new project.
git add
: This command adds the changes made to the files in the working directory to the staging area, where they can be committed.
git commit
: This command creates a new commit with the changes in the staging area. It requires a commit message to be provided.
git push
: This command pushes the local changes to the remote repository, updating it with the latest changes. It requires appropriate permissions and access credentials to be set up.
git pull
: This command fetches the latest changes from the remote repository and merges them with the local branch.
git status
: This command shows the current status of the repository, including the files that have been modified, added or deleted, and whether they are in the staging area or not.
git branch
: This command lists all the branches in the repository and allows users to create, delete, and switch between branches.
git merge
: This command merges changes from one branch to another, typically used to incorporate changes from feature branches into the main branch.
git clone
: This command creates a copy of a remote repository in a local directory, allowing users to work on it locally.
git log
: This command displays a history of all the commits made in the repository, along with their commit messages, timestamps, and other details.
Here’s the ranking of Git commands by significance:
git init
git add
git commit
git push
git pull
git status
git branch
git merge
git clone
git log
We’ve reviewed the top 10 commonly used Git commands and ranked them by order of significance or by how frequently they are used in day-to-day Git workflows.
Was this article helpful to you? If so, leave us a comment below. We’d love to hear from you!
Related Posts
When it comes to popular text editors for Linux, text editors are like wallets. Everybody’s got one and more importantly, everyone’s choice of a text
In this article, we will review installing and using Git on Linux machines. Besides minor differences in syntax, the install commands and procedures are similar
In this article, we will examine installing and using Gitlab on Ubuntu server version 20.04. Gitlab community edition or Gitlab CE can be installed by