Commonly used Git Commands

To set Visual Studio Code as Core Editor for Git. This command requires “code –wait” command working from command prompt, if not, then you may Add code to PATH environment variable and check the “code –wait” command working from command prompt OR you may replace “code” by actual path to code.exe

git config --global core.editor "code --wait"

Once above command is run, you can edit Git config in Visual Studio Code with below command

git config --global -e

Open global config with Visual Studio Code with above command and paste below lines in opened .gitconfig file which will set Visual Studio Code to be used as default tool for git difftool command

    tool = default-difftool
[difftool "default-difftool"]
    cmd = code --wait --diff $LOCAL $REMOTE

To check graphical view of commit history. Press ‘q’ to exit

git log --oneline --graph

Use below command to compare all the files in version before last commit and last commit, make sure you have set Visual Studio Code as default tool as mentioned above:

git difftool HEAD^ HEAD

To create new branch called feature

git branch feature
git checkout feature


git checkout -b feature

To merge above created feature branch to master

git add --all
git commit -m "commit message"
git checkout master
git merge feature

To pull changes from remote repo to local master branch and rebase master branch on the changes in remote repo.

git checkout master
git pull --rebase

To revert changes to specific unstaged file

git checkout -q -- <path_of_file>

To see difference between two files

git diff <path_of_file1_tobecompared> <path_of_file2_tobecompared>

To add untracked changes to changes to commit stage

git add --all

To check status of current commits, added changes etc.

git status

To check commit history

git log --oneline --graph

To push changes on master branch to remote repo named origin. Flag -u should be used only when you are pushing local branch to remote branch for the first time.

git push -u origin master

Sponsored Links

Azure DevOps with SharePoint Framework Apps

You might have developed SharePoint Framework (SPFx) apps before, but have you ever looked to automate build pipeline for your app so that your builds, tests and releases could all be automated? If so, you are at the right place. In this article. I have tried to gather all the steps that you would have to go through to setup basic build automation process for your SPFx app.


In order to follow the steps in this article, you will need to have following things already setup:

  1. Azure DevOps services account. If not having this account, then you can opt for one from here.
  2. Azure DevOps project
  3. Working SPFx solution
  4. Azure DevOps repo populated with source code for your SPFx solution

Steps to automate the build process with YAML:

  1. Open Azure DevOps project from
  2. Make sure you have updated scripts section in package.json of your source code and added package-ship and build-ship as shown below:build_package-json
  3. Make sure that your source code is already uploaded to Azure DevOps project’s repository which is named as spfx for example. By clicking on Repos, you should be able to see your source code and commit history.
  4. Click on Pipelines -> Builds -> + New -> New build pipeline. In the new yaml based editor, select the repo which hosts your source code, in our case you need to click Azure Repos Git build_connect
  5. In Select step, you will be provided with all the available repos. You need to select your repo namely spfx. As soon as you select your repo, azure will start analyzing your repository to suggest you compatible template.
  6. Azure will suggest multiple compatible options, you need to select Node.js under Configure section which will make you move forward to Review section where you will be presented with azure-pipelines.yml file.
  7. Replace everything from “- script: |”  line 18 in azure-pipelines.yml filebuild_yaml_to_be_replaced

    with following lines such that azure-pipelines.yml file will look like below screenshot:build_yaml

  8. We have now completed the yaml build. You may click Save from Save and run dropdown to save this yaml or you may choose to click Save and run to save and run the build immediately. Please note that save operation will commit azure-pipelines.yml to spfx repository for which you will need to enter required commit message and you may choose to either commit directly to master branch or you may create a new branch for this commit. For now, you may choose default options and click Save button to commit yaml build file.
  9. Click Queue button to queue your build so that you can check if our yaml build works fine and creates required artifactsbuild_queue
  10. Clicking queue button opens following dialog where you need to select the master branch assuming you have latest working code committed in that branch then select Run to kick-off the build process online.

  11. Build process will find available build agent in azure and perform tasks defined in azure-pipelines.yml file on the available build agent.build_queue_run_findagent
  12. If everything was setup correctly, then you should see all success messagesbuild_successful
  13. If you click Artifacts button then you will see following artifacts generated by the successful build process in drop folder as defined in our yaml build file:build_artifacts

Thanks for your patience. Hopefully this article helped you create your yaml build and run it with Azure DevOps. Do post your comments and let me know in case you have any queries. I will soon post next article in this series where I will take this build to next level and discuss creation of release and deployment stages.

Sponsored Links

Create copy of list using PowerShell

Use below script to save list to be copied as template and then create copy of list from the newly created list template.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$webURL = ""
$listName = "MyList"
$newListName = "Archived $($listName)"

# Use 0 below if you want to copy only list structure, 1 if you want to copy list data along with structure
$saveListDataWithTemplate = 0 

$web = Get-SPWeb $webURL
$site = $web.Site
$list = $web.lists | where {$_.title -eq $listName}
$list.SaveAsTemplate("$($listName)Template","$($listName) Template","$($listName) Template",$saveListDataWithTemplate) #stpfilename, title, description, bSaveListDataWithTemplate

$listTemplates = $site.GetCustomListTemplates($web)
$web.Lists.Add($newListName, "$($listName) list",$listTemplates["$($listName) Template"])
Write-Host "$($newListName) List created."

Please note that Posts list is unique in Blog site and hence we can not use above script for creating copy of Posts list in blog site. You get below error when you try to use this script for Posts list in blog site in SharePoint 2010:

"There can only be one instance of this list type in a web.
An instance already exists."

Sponsored Links

Export and Import Sharepoint Site with powershell

Export site from $webURL and import it to $newWebURL URL

Note: Please update $webURL, $newWebURL and $exportFilePath as per your environment.

Add-PSSnapin "Microsoft.Sharepoint.Powershell" -ErrorAction SilentlyContinue
$webURL = ""
$newWebURL = ""
$exportFilePath = "c:contoso.cmp"

Export-SPWeb -Identity $webURL -IncludeUserSecurity -IncludeVersions All -Path $exportFilePath

$web = Get-SPWeb -Identity $newWebURL
if($web -eq $null)
    write-host "Site Not found at $($newWebURL). Hence creating new site"
    $webTempID = (Get-SPWeb $webURL).WebTemplateId
    $webTemplateName = (Get-SPWebTemplate | Where { $_.ID -eq $webTempID } ).Name
    Write-Host "Site template name $($webTemplateName)"
    New-SPWeb $newWebURL -Template $webTemplateName

Import-SPWeb -Identity $newWebURL -IncludeUserSecurity -UpdateVersions Overwrite -Path $exportFilePath

Sponsored Links

Delete Sharepoint list items with PowerShell

Many a times in SharePoint, we have a need to archive old items as a list grows in size. After moving items to different list or exporting the list items to excel, we may have to delete exported old items from main list.

We may use following PowerShell script to delete list items having Modified Date older than 7 days.

Note: You may have to change $webURL,$listName and $caml variable to suit your requirement. CAML present in $caml variable is very crucial and need to be updated to select required set of items from list for deletion.

Most importantly this script can process large lists too as it fetches list items in batches

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$webURL = ""
$listName = "Posts"
$caml = "<Where><Leq><FieldRef Name='Modified' /><Value Type='DateTime'><Today OffsetDays='-7' /></Value></Leq></Where>"
$web = Get-SPWeb $webURL
$list = $web.lists | where {$_.title -eq $listName}
Write-host "List $($list.title) has $($list.ItemCount) items"
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.RowLimit = 2000
$spQuery.Query = $caml
$j = 1
   $listItems = $list.GetItems($spQuery)
   Write-host "Deleting " $listItems.Count " items in iteration $($j)"
   $spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
   $i = 0
   #Deleting all list items
   while($i -lt $listItems.Count)
      Write-host "Deleting item " $i " " $listItems[0].ID "-" $listItems[0].Title "." -foregroundcolor red
      $i = $i + 1
   $j = $j + 1
while ($spQuery.ListItemCollectionPosition -ne $null)

Sponsored Links

Create your website at
Get started