Using Git Commands

Git is a free and open source distributed version control system The following table lists the predefined Source Control commands in Source Insight, and useful settings for using Git.

Git has many fine-grained commands and concepts that go beyond the relatively simple source control con­cept used in Source Insight. The following table is one version that you may find useful. You can always add more custom commands in Source Insight for addition Git commands.

Table 3.4: Git Source Control Commands

Custom Command

Run String

Description

Check Out

n/a

With Git, there really isn’t a need to check a file out first. Simply modify your copy of the file as you want. Use the "Check In" command to commit your change when you are done.

Check In

git commit %r -m ""

Commit the current file to your local repository without comment.

Undo Check Out

git checkout -- %r

This command actually undoes the modifications to the file since you last committed the file.

Sync to Source Con­trol Project

git pull origin

Pulls new changes from the remote repository and updates all files in the current branch.

By default, "origin" is the name of the repository you first cloned from. If you have a specific reposi­tory you want to pull from, you should replace "origin" with the name of the repository.

Git pull will perform merges as needed if you have both local changes, and changes in the remote version of a file since you last pulled the file.

Sync File to Source Control Project

git fetch origin;git checkout FETCH_HEAD -- %r

Effectively pulls changes for a sin­gle file from the remote repository.

Edit each of the above Custom Commands, and set the "Run" string from the above table.

A shortcut to edit a Custom Command is to hold down the Ctrl key while clicking on one of the source control icons in the toolbar. For example, Ctrl+click on the "Check Out" button. The Custom Command dialog will appear open to the "Check Out" command.

The %r parameter in the "Run" string of a custom command will be replaced with the path of the current file relative to the project’s root source directory.

The git.exe and associated executables must be on your PATH.

Additional Git Information

Before you can use the commands above on a given file, the file must be part of the Git repository. To add a new file to your local repository, use the "add" command:

git add <file>

And follow it by:

git commit -m "here is my comment"

By default, "origin" is the name of the repository you first cloned from. If you have a specific repository you want to pull from, you should replace "origin" with the name of the repository. In addition, if you need to pull from a specific branch of the remote, you should specify origin <branch-name> in the commands.

You will need to install Git and initialize your local repository with the git init command before using any of these commands. Furthermore, you can configure Git so that the Git commands automatically work with your remote repository.

For information on Git, please refer to https://git-scm.com/