Git Useful Commands

There are Git Command line which are use full for developer.

Git Initialization:

Additionally, Git does not require any pre-existing server or admin privileges. All you have to do is cd into your project subdirectory and run git init, and you’ll have a fully functional Git repository.

$ git init

We can set up repository on Remote Git servers like git-hub, git-lab, bit bucket etc.

Define Remote address:

$ git remote add origin

Then push your project file into remote.

$ git push -u origin master
$ git config --global "Prakash Bhandari"
$ git config --global""
Add Username and Email for sync remote and local data.

Show the remote path or git which is cloned or added origin::

$ git remote show origin

We can use Git clone command if we have already exiting project.

Sometime we get error on pulling local file to origin. error like that

the solution would be ::

The error is resolved by toggling the allow-unrelated-histories switch. After a git pull or git merge command, add the following tag:

git pull origin master --allow-unrelated-histories

$git clone <project_url>

Show all Local or Remote Branch

-a shows all local and remote branches, while -r shows only remote branches.

$ git branch   [ Show all local Branch]
$ git branch -a   [ Remote and Local Branch]
$ git branch -r   [ Show all remote Branch]

How Does Git Checkout Remote Branch Work?

Git checkout remote branch lets us switch to (and work on) a remote branch, just like we’d switch to a local one. There are a couple of ways to do this.

First, fetch the remote branches:

git fetch origin

Next, checkout the branch you want. In this case, the branch we want is called “branchxyz”.

git checkout -b branchxyz origin/branchxyz

Or you can use:

git branch branchxyz origin/branchxyz

With newer versions, you can simply use:

$git fetch

$git checkout branchxyz

Rename a Branch

To rename a branch, run the command:


# Alternative

Delete a Branch

Git won’t let you delete a branch that you’re currently on. You first need to checkout a different branch, then run the command:

$git branch -d BRANCH-TO-DELETE

# Alternative:
$git branch --delete BRANCH-TO-DELETE

Compare Branches

You can compare branches with the git diff command:


Set Git username for repository [commit environment]

Setting your Git username for every repository on your computer

  1. Open Git Bash.
  2. Set a Git username:
    $ git config --global "Prakash Bhandari"
  3. Confirm that you have set the Git username correctly:
    $ git config --global
    > Prakash Bhandari

Setting your Git username for a single repository

  1. Open Git Bash.
  2. Change the current working directory to the local repository where you want to configure the name that is associated with your Git commits.
  3. Set a Git username:
    $ git config "Prakash Bhandari"
  4. Confirm that you have set the Git username correctly:
    $ git config
    > Prakash Bhandari


Git Laravel project setup in to local computer

Step 1:

Create a database locally named as your project name or wish utf8_general_ci

forexample we are creating laravel_cms database name and its collation into utf8_unicode_ci


Step 2:

Download composer

Pull Laravel/php project from git provider.

or place of your project file into your directory.



Step 3:

Rename .env.example file to .env inside your project root and fill the database information. (windows wont let you do it, so you have to open your console cd your project root directory and run mv .env.example .env )

Step 4:

Open the console and cd your project root directory

>mv .env.example .env

$cp .env.example .env
$php artisan key:generate

to change .env.example file to .env file.


Step 5:

Setup your database setting in to project.

for command line

>vim .env

edit and set your database name, host, password



for my case i have these credential for the database system.


Step 6:


$composer install

$composer update


$php composer.phar install

it will create your vendor file for the laravel project.


Step 7:


$php artisan key:generate

It will create key for project CSRF token.


Step 8:


$php artisan migrate

it is for making table schema and its primary seeds(data) which are written in migration folder.


Step 9:


$php artisan db:seed to run seeders, if any.

Primary seeds(data) which are written in migration folder.


Step 10:


$php artisan serve


Create a new branch in git and manage these branches

In your github terminal or site, We need to keep our master branch clean, by clean I mean without any changes, like that you can create at any time a branch from your master. Each time that you want to commit a bug or a feature, you need to create a branch for it, which will be a copy of your master branch.

When you do a pull request on a branch, you can continue to work on another branch and make another pull request on this other branch.

Before creating a new branch, pull the changes from upstream. Your master needs to be up to date.

Create the branch on your local machine and switch in this branch :


$ git checkout -b [name_of_your_new_branch]

Change working branch :

$ git checkout [name_of_your_new_branch]

Push the branch on github :

$ git push origin [name_of_your_new_branch]

When you want to commit something in your branch, be sure to be in your branch. Add -u parameter to set upstream.

You can see all branches created by using :

$ git branch

Which will show :
* approval_messages
Add a new remote for your branch :

$ git remote add [name_of_your_remote] [name_of_your_new_branch]

Push changes from your commit into your branch :

$ git push [name_of_your_new_remote] [url]

Update your branch when the original branch from official repository has been updated :

$ git fetch [name_of_your_remote]

Then you need to apply to merge changes, if your branch is derivated from develop you need to do :

$ git merge [name_of_your_remote]/develop

Delete a branch on your local filesystem :

$ git branch -d [name_of_your_new_branch]

To force the deletion of local branch on your filesystem :

$ git branch -D [name_of_your_new_branch]

Delete the branch on github :

$ git push origin :[name_of_your_new_branch]

The only difference is the : to say delete, you can do it too by using github interface to remove branch :

If we want to change default branch, it’s so easy with github, in your fork go into Admin and in the drop-down list default branch choose what you want.

How to access server from SSH

First step to make Git Repository in server is login server through the SSH connection.

You can use any type of SSH connection tool like Bitvise SSH or Git Base.

I have connected though GIT Base, We need username, Domain name or Ip and Password of Root user to access server.


Creating File and Working in this file


$ nano index.html

It will create index.html file

we can insert text and information on that file.

Vim create or edit file in Vim

$ vim prakash.txt


it will create file name prakash.txt, we  can now insert(write) text in to the file.


it will run file to insert mode.

after finishing updating information.


Changing the name of a file

[server]$ mv file1.txt file2.txt

Delete a file using SSH rm command

rm myFile.txt

This will match all files starting with ‘myFile’ and ending in ‘.txt’ and delete them.

To delete a whole folder and its content recursively, you can use:

rm rf foldername/

Delete All file in the folder

To delete all files/folders in the current directory, without deleting the directory itself, you would need to use:
rm rf *

Delete a file without asking for permission with SSH

rm -f myFile.txt

Delete a file using WildCard

This will delete all .txt files

rm -f *.txt

Delete all files and the directory with SSH rm

rm -rf /path/to/directory

Delete file and display information

rm -v myFile.txt

Delete file while being prompted for it

rm -i myFile.txt

Directory from Remote host to the Local host

copy directory from remote system to local system


scp -r <user>@<remote_host>:<remote_dir> <local_dir>

Example :

$ scp -r d:

$ scp -r    F:/jpy


~/www/JOBP/vendor1 = Server file location

F:/jpy = Local location


Adding an existing project to GitHub using the command line

Adding an existing project to GitHub using the command line


  • Create a new repository on GitHub. To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub.
  • Open Git Bash.
  • Change the current working directory to your local project.
  • Initialize the local directory as a Git repository.

$git init

  Add the files in your new local repository. This stages them for the first commit.

$git add .
# Adds the files in the local repository and stages them for commit. 
To unstage a file, use 'git reset HEAD YOUR-FILE'.

Commit the files that you’ve staged in your local repository.

$git commit -m "First commit"
# Commits the tracked changes and prepares them to be pushed to a remote repository. 
#To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and 
#add the file again.

At the top of your GitHub repository’s Quick Setup page, click to copy the remote repository URL.


In the Command prompt, add the URL for the remote repository where your local repository will be pushed.

$git remote add origin remote repository URL
# Sets the new remote
git remote -v
# Verifies the new remote URL

  Push the changes in your local repository to GitHub.

$git push origin master
# Pushes the changes in your local repository up to the remote repository 
# you specified as the origin


Git Commands

Git Initialize


To initialize a git repository in the root of the folder, run the git init command: $ git init Commiting Specific file : what is commit command  $git add -A – $ git add <filename> [add specified file] – $git add -A [add all files in to repository] Show the changes status of file



D:\ > $ git status  

D:\ > $ git status  :: Create a new branch::



$ git checkout <my branch name>

$ git checkout -b <my branch name> [create new branch as name specified] ‘$ git checkout <my branch name>  [go to specified branch ] go back to master repository



$ git checkout master 

$ git checkout master See whethere branch is created or not you can use the git branch command to confirm that your branch was created:


$ git branch  

$ git branch

Create a new repository on GitHub


create online repository in github site copy this repository link See log


$git log $git log — graph [show log in graph]

$git log  push an existing repository from the command line’ section: into github site


$ git remote add origin push local repository master content in to online repository location :



Git Pull Fetch from and Integrate with another repository or a local branch.

$git pull [options] [<repository> [<refspec>…​]]

$git pull origin master



Git Add changes (modified) local file


Stage your changes

Git has a staging area, for files that you want to commit. On GitHub when you edit a file, you commit it as soon as you save it. On your machine, you can edit a number of files and commit them altogether.

Staging a file in Git’s terminology means adding it to the staging area, in preparation for a commit.

Add your amended file to the staging area:

$git add <filename>
Ex: $git add attendees_and_learners.rst


Commit your changes

git commit -m "added my github name"

When you’re happy with your files, and have added the changes you want to commit to the staging area:



Merge from branch


example branch is ratcv2 which is need to merge in to master branch.

1. Admin@Admin-PC MINGW64 /f/new (master)
$ git merge ratcv2


2. Admin@Admin-PC MINGW64 /f/new (master|MERGING)
$ git add -A


3. Admin@Admin-PC MINGW64 /f/new (master|MERGING)
$ git commit -m “download files – from branch”

this command will merge ratcv2 updates in to master if any conflict arises it has to be fixed before


Aborting Merge for branch:


git merge –abort




 Push your changes to GitHub


When you made a change on GitHub, it not only saved the change and committed the file at the same time, it also showed up right away in your GitHub repository. Here there is an extra step: we need to push the files to GitHub.

If you were pushing changes from master locally to master on GitHub, you could just issue the command git push and let Git work out what needs to go where.

It’s always better to be explicit though. What’s more, you have multiple branches here, so you need to tell git where to push (i.e. back to the remote repository you cloned from, on GitHub) and what exactly to push (your new branch).

The repository you cloned from – yours – can be referred to as origin. The new branch is called amend-my-name. So:

$ git push origin amend-my-name


$ git push -u origin master

$ git push -u origin master Push a branch to GitHub


$ git push origin <yourbranchname>

$ git push origin master [ push in to master repo or we can push into created branch ]

Copy and Rename file


Installing and set up process of Laravel projects


change .env.example file to .env file $ cp .env.example .env now set up you database connection configuration — of .env file DB_HOST=localhost DB_DATABASE=ribbon DB_USERNAME=root DB_PASSWORD= +++++++++++++++++++++++++++++++++++++

Run composer



$ composer install


Migrate Database


$ php artisan migrate


Seed database : $php artisan db:seed

Sub Version control (GIT in windows) – git simple guide

This is just a simple guide for getting started with git. no deep knowledge 😉



Download git set up file



create a new repository




Cloning an Existing Repository – (Similar to Checkout SVN)

If you want to get a copy of an existing Git repository – for example, a project you’d like to contribute to – the command you need is git clone. If you’re familiar with other VCS systems such as Subversion, you’ll notice that the command is “clone” and not “checkout”. This is an important distinction – instead of getting just a working copy, Git receives a full copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down by default when you run git clone. In fact, if your server disk gets corrupted, you can often use nearly any of the clones on any client to set the server back to the state it was in when it was cloned (you may lose some server-side hooks and such, but all the versioned data would be there – see Git on the Server for more details).

You clone a repository with git clone <url>. For example, if you want to clone the Git linkable library called libgit2, you can do so like this:

$ git clone

That creates a directory named libgit2, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new libgit2 directory that was just created, you’ll see the project files in there, ready to be worked on or used.

If you want to clone the repository into a directory named something other than libgit2, you can specify that as the next command-line option:

$ git clone mylibgit


Git Basics – Getting a Git Repository


How to create repository of SVN?

What is SVN Server?

VisualSVN Server allows you to easily install and manage a fully-functional Subversion server on the Windows platform. It can maintain an Apache Subversion server on the Windows platform. for file and sharing option to the.

Download Visual SVN Server


We need to install the SVN server on our computer. There have following stages to crate svn repository.

How to Create SVN repository?

I have assumed the repository folder name onsnews for below example.

Step1 : open the system file in installed location of VisusalSVN Server Manager.


Step 2: Create new Repository. [the server interface displays the creating of repository area. create repository as same below the image.]


[ After Create the repository folder It Creates three sub folder [i. branches, ii. tags , iii. trunk] in every repository]


Be confirm to check the button [Create default structure (trunck, beanches, tag)]

Copy the URL to clipboard of the created folder.

There would be link in this form we need to replace the name by ip


replaced ip


After copying the Repository link

Go to your project folder

Right click choose TortoiseSVN  –> Import …


It puts files and folder in SVN Server

We need to confirm it is on the copied on server

 {repository} >> {project_folder_name} >> trunk=> {list of imported files}.

It displays all imported data available from previous stage on Trunk folder.


In the previous stage we find the data are on SVN repository server. Then we need to sink the data from local and server machine.

Our above folder onsnews folder in the D:\wanp\www

Have need to sink to our SVN server.

Right Click on the folder name which you want to replicate from svn server

SVN Checkout =>

Make sure that the repository folder name with

Syntax: https//{computer server ip}/{project repository name}/trunk


Checkout directory is path of your local folder what you want to checkout.

Example Like