Most wanted GIT Commands..







Need some simple GIT commands to learn? You have arrived at the right place. Read on to find out about our handy cheat sheet that you can use on a daily basis.


Let's continue with it!


GIT is the most commonly used open-source VCS (version control system) for monitoring file changes. Normally, businesses and developers use GIT to collaborate on computer and applications creation.


Understand the process of the GIT


A GIT project is made up of three main sections:

  • working directory

  • staging area

  • git directory

You can add, delete and edit the files in the working directory. Then in the staging area, the changes are staged (indexed). The snapshot of the changes will be stored in the git folder after you commit the changes.


For Linux, Windows, Mac, and Solaris, everybody can use GIT. The programs may have a steep learning curve, but many guides are available to assist you.


Basic GIT Commands

Here are some basic GIT commands you need to know:


git init : will create a new local GIT repository. The following Git command will create a repository in the current directory:

git init

Additionally, by specifying the project name, you can create a repository in a new directory

git init [project name]

git clone : Used to copy a repository. If the repository lies on a remote server, use:

git clone username@host:/path/to/repository

To copy a local repository, run the following basic Git command:

git clone /path/to/repository

git add : Used to add the staging area data. For example, the following basic Git command indexes the temp.txt file:

git add <temp.txt>

git commit : A snapshot of the changes will be generated and saved to the git directory.

git commit –m “Message to go with the commit here”

git config :User-specific configuration values such as address, password, file format, and so on can be set. The email setup order will look like this to illustrate:

git config --global user.email nawab@example.com

The –global flag informs GIT that for all local repositories you will use that address. Use the command below if you want to use various emails for specific repositories:

git config --local user.email youremail@example.com

git status : Shows the list of files that have been updated and the files that are still to be staged or committed.

git status

git push : Used to submit local commitments to the remote repository master branch. Here is the structure of the basic code:

git push origin <master>

Replace <master> with the branch where you want to push your changes.


git checkout : Build branches and help you navigate between branches. The following basic Git command, for example, creates a new branch and switches you to it automatically:

command git checkout -b <branch-name>

To switch between branches, simply use:

git checkout <branch-name>

git remote : Allow all remote repositories to be viewed. The following control lists all connections together with their URL's:

git remote –v

Use the following command to link the local repository to a remote server:

git remote add origin <host-or-remoteURL>

In the meantime, the following command will delete a remote repository connection:

git remote rm <name-of-the-repository>

git branch : Creates, lists, or deletes divisions. If you want to list all the branches in the database, for example, the command will look like this:

git branch

If you want a branch to be deleted, use:

git branch –d <branch-name>

git pull : Merges all modifications to the local working directory in the remote repository.

git pull

git merge : Use the branch to merge into the active one.

git merge <branch-name>

git diff : Lists the disputes. Use to show conflicts with the base folder

git diff --base <file-name>

To display conflicts between branches before merging them, the following basic Git command is used:

git diff <source-branch> <target-branch>

To list all conflicts present, use:

git diff

git tag : Specific obligations tag. Normally developers use it to mark release points such as v1.0 and v2.0.

git tag <insert-commitID-here>

git log : Used to access the database history by listing the information of certain commit. You will get an output that looks like this when you run the command:

commit 15f4b6c44b3c8344caasdac9e4be13246e21sadw
Author: Alex Hunter <nawab@example.com>
Date:   Mon Oct 1 12:56:29 2016 -0600

git reset : The command resets the index and working folder to the state of the last commit.

it reset --hard HEAD

git rm : Can be used to delete files from the working directory and index.

git rm filename.txt

git stash : Order saves changes that are not ready to be made immediately. You can then return to that project later.

git stash

git show : Is a command used to display any git object data.

git show

git fetch : Allows users to pick up from the remote repository all objects that actually do not reside in the local working directory.

git fetch origin

git ls-tree : Allows you to display a tree object with each item's name, mode, and SHA-1 value of the blob. Let's presume you're looking for the HEAD, use:

git ls-tree HEAD

git cat-file : Use to show the database object type and size data. Use the -p option to view the details of a specific object together with the SHA-1 value of the object, for example:

git cat-file –p d670460b4b4aece5915caf5c68d12f560a9fe3e4

git grep : Allows users to scan for unique phrases and words through committed trees, working directory, and staging area. To scan for all files for mncinterviewquestions.com, use:

git grep "www.mncinterviewquestions.com"

gitk : Displays the local repository's graphical interface. Just run:

gitk

git instaweb : Allows you to search through the git-web interface of your local server. For instance:

git instaweb –httpd=webrick

git gc : Clean and optimize the local archive for unwanted files.

git gc

git archive : Allows users to create a zip or tar file with a single repository tree node. For instance:

git archive --format=tar master

git prune : Deletes objects with no incoming references.

git prune

git fsck : Conducts a git file system integrity check and detects any compromised artifacts.

git fsck

git rebase : Used for some branch-to-branch shifts. For instance:

git rebase master
These are the commands I believe are essential to make things happen, at least for me. Post here if you think anything important has been overlooked or something can be done differently reach back to me or comment below!!
0 views
Never Miss a Post. Subscribe Now!

Contact Us: nawabblog@gmail.com

Location : Bangalore India.

© 2019 proudly created  by Nawab Ahmad. 

  • Nawab Ahmad
  • Grey Twitter Icon
  • Nawab Ahmad