Git and Visual Studio Online Source Control Operations

Git and Visual Studio Online Source Control Operations

Released Date: 05/16/2025
Version: NA

This document shows the operations with using git and Visual Studio online for source control operations. Generally speaking, the following are stages of where the modified source codes are saved:
  1. Modified Changes - You use the "save" option in VS codes to save.
  2. Stage Changes - You use the "git add <file>" or "git add ." to stage.
  3. Commit Changes - You use "git commit" to commit your current branch staged files.
  4. VS Online in a branch - You use "git push" to push your local committed changes to VS online. We never directly push to the main branch.
  5. VS Online in main branch - You create a pull request to get other developers to comment on your changes.  Then you can use "complete" to merge your changes in the branch with the main branch.  The complete function will also go through the pipeline to deploy to the final destination.

Before Starting to Make Changes in VS Code

Before starting to make changes to your VS Code locally, please bring up VS Code, In the terminal, perform the following:

  1. git checkout main: Use "git checkout main" or "git switch main" to make sure you are on the main branch. 
  2. git pull: Use "git pull" or "git pull origin main" to bring down the latest main branch, and it will also synchronize with main and any sub branch and merge them.
  3. git branch -d <branch>: This is optional. If I previously had a branch that's already pushed, pull requested and completed, then I should delete that branch locally. You can find out all location branches by using “git branch”.
  4. git checkout -b <branch>: Since we never modified the main branch, this will create a <branch> and switch to that branch. Your modification will be in this <branch>.
Now you are ready to make changes to the VS Code on your local machine.

Making Changes in VS Code and Git Options

Saving Changes in VS Code can be broken down into the following steps:

            Save, Stage(add), Commit, Merge(pull), Push, Create Pull Request and Complete

1.      Save: This involves clicking on the “save” or “save all” in VS Code.  This is then considered as a “modified change." But it is not saving to git yet.

2.      Add: This is to add the changes you made and saved (in modified changes) to the git staging area.  You can use the following command:

·               “git status”

o   This will show what branch you are on and what’s modified.

·               “git add <file>” or “git add .”

o   You can either add one changed file to the staging area or use the shortcut “git add ." to add all changes to the staging.  We typically use “git add .”

o   At this moment, the changes still only reside locally.

      "stage change"
                  o   You can also use the UI under the source control to stage all the changes. This will get it ready for the commit step next.

3.      Commit: This is assuming all changes for a particular purpose are completed. When you do so, the system will prompt for a description of what you did.  Use the format decided on by the  team.

·               “git commit”

This commits all changes in the staging area and commits them locally to the commit area. It will open notepad++ with some default. If the notepad++ does not show up, just press "ENTER" key to cause notepad++ to show up. Delete everything. An example follows for the first line:

                  change CustomerRecordDefaultColumn.tsx for default screen

The first line represents the title line. Press the Enter key twice to create a blank line.  Starting from the third line is the detailed description of your changes. The following are sample descriptions:

  1. Remove the FFL literal
  2. Combine City, State, Zip into one line
  3. Remove FFL field
Note that the description supports mark down syntax. So you can put “*” at the beginning of each line in the above examples to become bullet points.
Save the notepad++ file (Vince is not sure if save is required).
According to document, you can also use git comment -m "Fix customer validation" as an alternative method.

4.      View Log: This is an optional step. You can use this step to get a history of everything you changed so far before going on to the next step to merge with the server.

·               “git log”

o   In the log interface, use the arrow key to scroll up and down -- don’t use the scroll bar.

o   Type “q” to quit review.

5.      Merge: This is a recommended step that allows you to merge the latest changes from VS online if you have multiple developers working on the same project.  If there’s a merge conflict, you can resolve it locally, which is much easier.  If you don’t do this, then in the next step when you push your changes, it is a lot more difficult to resolve the merge conflict online.

·               “git pull origin main”

o   This will go to the remote server (i.e. VS online) and download the main branch, and merge with main and the current branch (e.g., config\EMKChange).

o   If it can’t merge automatically, you will have to merge it manually.

o   Again, if you don't do this step, then when you try to push to the server and it has merge conflict, it is much more difficult to resolve at that point.

6.      Repeat Steps 1-5 to make additional changes until you are ready to push your codes. You can choose to push one change at a time to make the process easier to operate.

7.      Push: This will save the changes to the server. Use the following command:

·               "git push origin <branch>" 

o   The <branch> may be like “config\EMKChange.”

o   You can now click on the link in the terminal to go to VS online.

On 7/2/2026, Vince suggest to use "git push" to let the system give you the full syntax. The command is somewhat different than above. Then copy the syntax and use it in terminal.

8.      Create Pull Request: In VS online, on the right side, you will see a message something like “you just push ….” And a link to allow you create the pull request.

·         The purpose of the pull request is to allow others to review your codes.  It also break down the changes that will be merged to the main in a easier to manage way.

When creating the pull request, keep the title in the Description. If you only have one commit, then the description of the commit will be at the end. Keep that. If you have multiple commits, then you should combine them.

9.      Complete: You can either complete it right away or wait for others to comment. Complete will merge your changes to the main branch.  If you get a merge conflict, you will have to manually merge it, which is not as easy as when you merge locally.

10.  Monitor: After you choose to complete, before you can pull to your local main again, you will need to wait to see if the complete is finished.  You can either wait for the email notification or go to the pipeline on VS online to see the progress.

 

Advance Options to Clean Up All Local Branches

Instead of deleting local branches one by one manually, the following PS command is an alternative for deleting all local branches other than main:

·               git branch | %{ $_.Trim() } | ?{ $_ -ne 'master' } | ?{ $_ -ne 'main'} | ?{ $_ -ne 'develop'} | %{ git branch -D $_ }

This command will get of all branches except main locally. We do not recommend using this option.


Procedure Recommended by ChatGPT

git checkout main                        # Switch to the main branch
git pull                                           # Get the latest changes from the remote
git checkout -b my-feature         # Create a new branch and switch to it

# Make changes...

git add .                                        # Stage your changes
git commit -m "My changes"     # Commit them locally
git push -u origin my-feature     # Push the new branch and set the upstream

After the first push with -u:

  • The branch is created on the remote.
  • Your local branch tracks the remote branch.
  • VS Code should no longer show Publish Branch.
  • Future pushes are as simple as:
git push

and future pulls are simply:

git pull

If you're using Git 2.23 or newer (most people are), git switch is a bit clearer than git checkout for branch operations:
git switch main
git pull
git switch -c my-feature

# Make changes... (click File -> Save or Save All) 

git add .  (or you can use the UI by click on the Source Control Icon, and click the + sign)
git commit -m "My changes"
git push -u origin my-feature

Now go to VS Online, create a pull request and choose to "Auto Complete". 
Wait for the auto complete to finish and come back to your local VS codes and perform the following:

git switch main
git pull
You can verify if the changes had been pulled down to the main branch.
git branch -d my-feature

git switch is specifically for changing branches, while git checkout has multiple purposes (switching branches, restoring files, etc.), so switch is often easier to read.

Overall, your workflow is exactly what many teams use:

  1. Update main.
  2. Create a feature branch.
  3. Make and commit changes.
  4. Push the branch with -u.
  5. Open a pull request when you're ready to merge.

EMK