Virtual Geek

Tales from real IT system administrators world and non-production environment

Step by Step guide to push your first project to

git github visual studio code git add all git commit -m message Fork from another repo git clone git pull git push infrastructure as a code iaas scripting devops.png

Part 1 Git version control integration in Visual Studio Code
Part 2 Git master branch source control integration in Visual Studio Code 
Part 3 Git clone version control integration in Visual Studio Code

I have already wrote few articles on how to use git earlier, but they where completely for Visual Studio Code,  GUI with little exposure to command line. In this article I will perform the same tasks using complete git commands. I have already downloaded and installed git application from Git is a command line tool a distributed version-control system for tracking changes in source code during my DevOps scripting development. It helps me to collaborate my all scripting work among my colleagues and acts as good Central repository, it also helps to track changes in any files and can check in going point in time to review what changes where made when committing/pushing files. Git works very well for local repository. is a central Git repository hosting service, but it adds many of its own features. GitHub provides a centralized Web-based graphical interface. It also provides access control and several collaboration features, such as a pull requests, wikis and basic task management tools for every day projects.

Solved Visual studio Code make sure you configure your and in git

First to start I have created an account on, After login create a new repository (Basically it is a folder/directory contains all the project code/scripts files, including revision history) by pressing + button on the right top side of the screen, select New repository from the list. Provide repository a name and description (optional), I am keeping this repo public so anyone can view it and we can also choose who can modify it to it by assigning permissions later. Press Create repository.

git create new repository public private git commands powershell code as a service automation infrastructure as a code ps1 .png

Once the repository is created This shows some very basic useful information regarding git command line introduction and how to quick setup. Grab/copy the git url location with HTTPS (Another protocol you can use is SSH), this will require later. git init git add git commit -m first commit git remote add orgin https .git git push -u origin master devops automation infrastructure as a code.png

I have opened my PowerShell and using oh-my-posh module to add flavors to my PowerShell console. That helps to enhances the prompt and git operations. I am creating a folder called Git-Demo.

New-Item -Path D:\Scripts -Name Git-Demo -ItemType Directory

I will keep all the my codes/script on the same directory later, go the the directory to Git-Demo.

Set-Location D:\Scripts\Git-Demo

It is empty. Run below command to initialize the empty repository on the folder, Every time you run git command keep eye on the prompt head it says master with color green (means there are no changes inside directory everything is up to date nothing to stage), it is a master root branch also can be called first base branch

git init

It creates .git folder, This folder contains actual version control with all the metadata regarding this local git repository, all the changes will be captured in the folders. I am creating first file call (I will call it help file, it has all the information regarding to my projects, scripts, howto etc.)

Write-OutPut "# vCloud-lab -Test Readme" >>

As soon as I generate a new file, prompt color changes to Yellow with +1, means there is new file added. (first digit with + plus letter represents new files count added to the folder, second digit with ~ tilda character says this much of files are modified, and the last digit with - minus sign indicate deleted files count), Because I have added a single file it is showing +1 as a count.

git.exe basics new-item -path scripts -itemtype directory set-location git init .git initialized empty git repository write-output powershell visual studio code master branch.png

The git add command adds a change in the working directory to the staging area. As below command I am only adding one file to the staging area, If you have multiple file you can use . (dot) or * (star) and keep checking status with git status. The git status command displays the state of the working directory and the staging area.

git add .\
git status

Next use Git Commit. The commit command is used to save your changes to the local repository, -m means message and it is mandatory.

git commit -m "first demo commit"

When I commit to the local repository, it immediately change the color of prompt with back to green color logs with 1 file changed, 1 insertion(+). As far all is good and everything is added to local repository nothing pushed to centralized github repo, now I can make as much as modifications to the files and keep adding and committing to local repo. All the code is stored locally, Before pushing the local changes to github, it requires to mention which online repository you want to push data, use the same HTTPS git url shown before. This is a one time command.

git remote add origin

Next start pushing data to online github repository.

git push -u origin master

When you add a remote url, try to push, for the first time it will try to authenticate to and prompts you for to add credentials. Because I am using it on visual studio code, it is asking me for additional permissions. I am using Windows 10, credentials are stored under your accounts Credential Manager in encrypted form so you don't have to type user name and password again. Regarding this if you are facing error check my article.

Remote: Permission to UserName/repo.git denied to OtherUserName fatal: unable to access '': The requested URL returned error: 403

git git comiit -message first commit git remote add origin https .git master repository master branch devops infrasturcture as a code iaac IAAS.png

Once file is pushed online you can view it on by refreshing it on browser. Now make few more tries, add, modify and delete files with git add, commit, push command and see the changes offline/online. git init git commit git add all files and folders branch code pull requests security pr tags actions infrastructure as a code iaas automation devops scripts.png

Next I will create a branch for better collaboration with my colleagues. A Git branch is essentially an independent line of development. It means me and my team will not make any direct modification/changes to the Master, in layman term instead I will copy the the Master folder, give the folder name, make changes on the copied folder, once work is done merge the changes with Master branch. if require delete the the branch I was working on to keep repository look cleaner. You can check the branches list with below command.

git branch

I have only one base branch - master and it is * starred means I am onto the branch, whatever changes I make, will be done under master branch, here also when I create new branch it will be created on top of selected * starred branch and data is cloned from the branch. Create a new branch using below command.

git branch vcloud-lab-projects

Now list the branches  again. New branch is populated, all the changes are stored locally it is not yet pushed online on GitHub, the web screenshot here shown only for information purpose.

git branch

To change branch and start working on new branch, use below command.

git checkout vcloud-lab-projects

Once branch is changed notice the head of prompt, it switches to new branch. Whatever changes we make will reflect here only and master branch will be untouched.

visual studio code git branch git checkout switched to branch default master repository tags git automation version control source control infrastructure as acode iaac infrastructure coding as a service.png

Next I have copied 2 powershell ps1 script files on the folder (using explorer), when I just use ls command the prompt changes to yellow showing 2 new files added. There are 2 untracked files. Add the all files in git. You can use below command to see the status and add untracked files

git status
git add .

Check the status again, run Commit with message to save them to git repository.

git status
git commit -a 'Add scripts to branch'
git status

Check the status again, prompt is green, This shows on which you are now, Nothing to commit, working tree is clean.

git stauts git add . git status git commit -m add scripts oh my posh powershell demo powershell as a code infrastructure as a code iaac service online bitbucket.png

You can view the changes online now by refreshing in browser, on the master branch there are no new files, click on the master button and choose the branch vcloud-lab-projects. All the newly added files are visible on the new branch now. change branch master code add files md help file add scripts to branch infrastructure as a code releases feature add git status commit add push pull.png

Next I will merge the changes made on from vcloud-lab-projects to master, I am still on the vcloud-lab-project, and to proceed further I will checkout to master branch.

git checkout master

Once switched to master branch you can verify no .ps1 files visible earlier added and there is still only sole file exist.

Microsoft Powershell visual studio code git demo ls git checkout branch master devops scripting infrastructure as a code IAAS source control version control git commit.png

Check the prompt I am on the master branch now. To start merging use below command.

git merge vcloud-lab-projects

list the files, all looks good, Check the prompt now, color changes to Magenta with up arrow, which means all the merging is done locally, To push it on online github repo, use below command.

git push

Refresh page and switch to master branch now you will see pushed files. git merge  master powershell automation ps1 git push ls infrastructure as a code iaas git commit master packages releases command git.exe basics.png

In the last, if you want to delete branch, once work is completed, below command helps you to perform the task on local git repository.

git branch -d vcloud-lab-projects

To delete branch on centralized repository use as below command.

git push origin -d  vcloud-lab-projects

Next refresh web page and verify by clicking master button, other branch no longer exists.

git branch -d deleted branch git push origin -d project up to date infrastructure asa code iaas coding as a service powershell automation devops delete.png

Useful Articles
Resolved: Git warning LF will be replaced by CRLF in file
Creating an internal PowerShell module repository
Powershell Azure Inventory GUI Utility

Go Back


Blog Search

Page Views


Follow me on Blogarama