How to use Git in Visual Studio Code

Before change code in dev branch, you need to ensure you had the latest change of the master branch.

  1. Check your current local branch by using ‘git branch‘.
  2. Use ‘git checkout master‘ to switch your current branch if you are not on the master branch
  3. Use ‘git pull‘ to get latest update from the master remote repository. This command will download the latest changes from the remote repository and merge them with your local master branch.
  4. Use ‘git checkout dev‘ to switch your branch from local master to local dev
  5. Use ‘git merge master‘ to merge the changes from master branch into your local dev branch

Now, local dev branch’s code is updated to the same as master remote repository then you can start your new code change in dev branch.

  1. Before you change start code change, always use ‘git branch‘ to check what’s your current branch. then start your code change
  2. Once you finished your code change, use ‘git status’ to check the status of your local repository. This will show you which files have been modified or added and which files are ready to be committed.
  3. Use ‘git add <file>’ to stage the changes your want to commit. or You can stage all changes by using ‘git add .
  4. Use ‘git commit -m “commit message” ‘ to commit changes with a message describing the changes made.
  5. Use ‘git push‘ to upload your commits to remote repository. this command sends your local commits to remote repository and make them available to others.
  6. a merge request should automatically created after ‘git push’ is done. this merge request will try to merge dev branch changes to master branch.

To checkout a remote branch from Visual Studio Code, you can follow these steps:

  1. Open the Command Palette by pressing Ctrl+Shift+P (Windows, Linux) or Cmd+Shift+P (macOS).
  2. Type Git: Checkout to... and select it from the list.
  3. In the prompt that appears, select origin/<branch-name> from the dropdown list of remote branches.
  4. Choose a local branch to create or overwrite, or leave it blank to create a new branch with the same name as the remote branch.
  5. Press Enter to complete the checkout.