Intro
When it comes to version control systems, there are few software that can beat GIT in performance and relevance. GIT was developed by Linus Torvalds in 2005 and today, millions of companies use it for efficient code management and version control of their projects. Open source software is available for download for Linux, Windows, Solaris and Mac platforms.
GIT Commands
git config
One of the most used git commands, email, username and file format etc. git config, which can be used to set user-specific configuration values such as the preferred algorithm for example, the following command can be used to set up email:
git config --global user.email root@baransel.dev
git init
This command is used to create a new GIT directory. Sample:
git init
git add
The git add command can be used to add files to the directory. For example, the following command will index a file named README.md
located in the local directory:
git add README.md
git clone
The git clone command is used for directory checking purposes. If the directory is located on a remote server, use:
git clone baransel@91.128.110.48:/path/to/repository
git commit
The git commit command is used to commit changes to the head. Note that not all committed changes will go to the remote directory. Example:
git commit –m "Message related to commit."
git status
The git status command displays a list of files that have not yet been added or that have been changed along with the committed files. Example:
git status
git push
git push is another of the most used basic GIT commands. With a simple push, it pushes the changes made to the master branch of the remote directory associated with the working directory. Example:
git push origin master
git checkout
The git checkout command is used to create or switch branches. For example, the following creates a new branch and switches to it:
command git checkout -b
To switch from one branch to another, use:
git checkout
git remote
The git remote command allows a user to connect to a remote directory. The following command lists currently configured remote directories:
git remote –v
This command also allows the user to mount the local directory to a remote directory:
git remote add origin
git branch
The git branch command can be used to list, create or delete branches. To list all branches found in the directory, use:
git branch
To delete a branch:
git branch –d
git pull
The git pull command is used to merge all the changes found in the remote repository into the local working directory. Example:
git pull
git merge
The git merge command is used to merge a branch into the active branch. Example:
git merge
git diff
The git diff command is used to list conflicts. To view conflicts with the base file
git diff --base
The following command is used to view conflicts between branches to be merged before merging:
git diff
git tag
Tagging is used to mark specific commits into simple parts. An example of this:
git tag 1.1.0
git log
Running the git log command will output a list of commits on a branch with the relevant details. An example output:
commit 11f4b6c43b3c8241caasraq9e4be13246e21sewd
Author: Baransel Arslan
Date: Mon Nov 8 12:56:29 2021 -0600
git reset
The git reset command is used to reset the directory and working directory to the last commit state. Example:
git reset --hard HEAD
git rm
git rm can be used to remove files from directory and working directory. Example:
git rm filename.txt
git stash
It is probably one of the lesser known basic git commands. It helps to temporarily save changes that will not be processed immediately. Example:
git stash
git show
Use the git show command to display information about any git object. Example:
git show
git fetch
git fetch allows a user to fetch these objects from the remote directory that is not currently in the local working directory. Example usage:
git fetch origin
git ls-tree
Use the git ls-tree command to view a tree object, along with the name and mode of each item, and the blob’s SHA-1 value. E.g:
git ls-tree HEAD
git catfile
Display the type of an object using the git cat-file command, with the SHA-1 value. Example:
git cat-file –p d674467b4b4aefe5322caf5c28d12f510a9he3e4
git grep
git grep allows users to find sentences and/or words through content trees. For example, to search for baransel.dev in all files use:
git grep "baransel.dev"
git gc
To optimize the repository by cleaning junk files, through garbage collection, use the following:
git gc
git archive
The git archive command allows a user to create a zip or tar file containing the components of a single directory tree. Example:
git archive --format=tar master
git prune
Via the git prune command, objects that do not have incoming pointers are deleted. Example:
git prune
git fsck
Use the git fsck command to check the integrity of the GIT filesystem. Corrupt objects are identified:
git fsck
git rebase
git rebase command is used to reimplement commits from another branch. Example:
git rebase master