Git is an open-source distributed variant system tool created to manage various projects with agility and adaptability. It was designed by Linus Torvalds in the year 2005 to improve Linux Kernel. Git has the functionality, administration, defense, and docility that most people need. You may now use Git with services like Github and Gitlab for creating free Git-based repositories with your code inside and then track all the changes.
The following is the list of important Git commands:
This command is one of the first git commands you should run after installing Git on your computer. It is used to configure your personal. profile and things such as username, email, domain and much more. The following example is displaying the use of git config to set the username and its email.
This is one of the git basic commands that you should use for a new Git repository. It starts a git repository and formulates the initial .git directory in a new or a previously created project. For example, the following command initializes the empty Git repository.
This command is one of the most used git commands. This command adds a file or files in the indexed working directory. For example, the following command is adding project1 in the indexed working directory.
git add project1
This command is the most widely used git command in the git commands list because you can use it to automatically download remote Git repository into your computer. It generates a copy of the Git repository from an old source. The command will also attach the primary spot as a detached location so users are capable to retrieve from it again and push. For example,
git clone firstname.lastname@example.org:jeff/mydir.git
The “commit” in git commit is applied to save the changes to the git repository. It takes all of the modifications addressed in the index, generates a fresh commit object aiming to it, and inserts the git branch to the new commit. For, example, the following command is using git commit.
This Git command displays the status of records in the index against the functioning directory. It displays files that are not tracked, altered, tracked but not updated, and already in the queue for committing. The following example will display status.
This command displays the file discrepancies. In other words, this command displays the differences which are still not staged. With the help of this command, the differences between the two branches can also be displayed. The git branch is just a movable pointer. For example,
This is the most significant command for git list branches. It displays current branches, such as distant branches if extension ‘-a’ is mentioned. It can also produce a new git push branch if a branch name is given: For example
This is one of the common git commands. As the name suggests, it can merge one or more git branches into your existing branch. It also implicitly forms a new commit if there are no disputes. The git merge command allows to use the self-governing lines of development produced by git branch and combine them into a separate branch. It is important to note that all of the commands merge into the existing branch. For example, the following command is displaying the use of merge command.
The git reset is one of the useful git commands. This command resets the index and current working directory to the condition of your last commit. This is just like a rollback but up to the last commit. The git reset is an important command that is utilized to undo local modifications to the nature of a Git repository. Git reset works on the three trees. These trees are the Commit History ( HEAD ), the Staging Index, and the Working Directory.
For example, the following command resets the myfile.css up to the last commit.
This is one of the most useful git cmd commands. This command is used to delete the file from the current directory and stages the removal. For example, the following command removes the testfile.txt from the current directory.
git rm testfile.txt
This is one of the most important git command-line tools. The checkout command is used to switch from one git branch to another. For example, the following command is displaying the use of checkout command to switch to branch_3
The git pull request is one of the most used git commands. It retrieves and merges variations on the distant server to the current working directory. For example, the following command is displaying how to retrieve the variations on a remote server.
The git push command is one of the most important git commands. This command is used to push all the updated or remodeled bounded objects to the remote git repository and develop its git branches. For example, the following command is displaying the use of push.
This is one of the most useful git commands. It is used to display all the remote variant of the git repository. A remote repository in Git is a public repository that developers utilize to swap their changes. For example, the following command is displaying the effective use of git remote command.
The git log command is one of the most crucial commands. It is used to display all the commits on a git branch and display the analogous details. The Git Log command enables the user to observe data about earlier commits that have transpired in a project. The purest variant of the log command displays the commits that drive up to the status of the checked out git branch. The following example is displaying the use of git log command.
The git archive is one of the common git commands. This command is used to create a zip file that involves the data of a private tree from the git repository. It also generates an archive of the defined setup comprising the tree structure for the selected tree and addresses it out to the conventional output. The following example is displaying the use of git archive command.
This command is one of the top git commands. It works as a garbage collector. This command is used to collect garbage from the git repository. The great thing about this command is that it is also used to optimize the repository. It should be run periodically. The following example is displaying the use of git gc
After running the above command it produces the following result:
This command is one of the most crucial git commands. It is also known as a File System Check. The name is just like that of Unix fsck command. It is also used to validate a file system. The git fsck command will conduct an integrity analysis of the Git file system and recognize infected objects. For example, the following command will perform the integrity analysis.
The git stash command is one of the most useful git commands. This command is used to tentatively saves all the altered traced files. In other words, stashing is responsible for taking the modified tracked files and staged modifications and saves it on a stack of incomplete developments that the user can apply at any time. The following example is displaying the use of git stash
This command is one of the most useful git commands. It is used to eliminate objects that are no longer aimed by any object in any branch. The git prune command is an in-house service that sweeps up orphaned objects. These objects are those that are difficult to access by any refs. Prune is recognized as a garbage accumulation command and is a subordinate command of the git gc. The following example is displaying the use of git prune command.
This command is the command that helps to clean from non-tracked files in your Git repo. Sometimes if you have lot of files generated during compilation or work of your application you may need to have a way to quickly remove them to avoid accidental addition of these files into the main Git repository/
git clean -n – will simulate the removal of all the untracked files in your repository
git clean -n "*.log" – will simulate removal of all the untracked *.log files
git clean -f "*.log" – will remove all the untracked *.log files from the current repository
The above git commands cheat sheet is crucial for any developer. One of the most important benefits of Git is its branching abilities. Unlike centralized variant control networks, Git branches are standard and simple to merge. This helps the branch workflow successful with many Git users. Feature branches present a remote environment for each modification to the codebase.
The feature branch workflow also gives adaptability when preferences shift. For example, if you’re midway through a release period and you want to delay one characteristic instead of a different time-crucial one, it can also be done.