Tutorial: Getting started with Git in MPS
This tutorial will guide you through the most popular Git operations and show how they can be performed in MPS. You will learn how to create Git repositories from your projects, share them on GitHub, commit and push changes, create and merge branches, resolve merge conflicts, and investigate the files' history.
Step 1. Create a new project with a Git repository
In this tutorial, we will create a simple project, share it on GitHub, and perform some Git tasks.
Launch MPS and click New Project on the Welcome screen.
In the dialog that opens, select the project type (for this tutorial, we will create just an Empty Project), specify the name of the project (for example,
gitdemo), and provide the location path.Select the Create Git repository checkbox.

Click Create. The new project will open in MPS.
You will get a notification that the local Git repository has been created for your project. Also, dedicated tool windows for working with Git become available.

Git Branches popup: manage Git branches and perform basic Git operations.
Commit tool window (Ctrl+K or ): review the local changes and commit them to the local Git repository.
Git tool window (Alt+9 or ): work with the Git log and more.
Step 2. Add files to Git
Once the Git integration is enabled, MPS shows which files have been modified, which new files have been added to Git, and which files are not being tracked by Git.
To learn how it works, let's create a simple README.md file with a short description and add it to Git.
In the Project tool window Alt+1, select the project directory (
gitdemo).Click
on the tool window toolbar and select File from the list. Name the file
README.md.In the dialog that opens, click Add so that Git could start tracking the file.

Now when you modify this file, MPS automatically indexes any changes (in other words, adds them to the Git staging area) so that you do not have to do that manually.
Add the following text to the newly created file:
#Tutorial This is a tutorial where you will learn how to create Git repositories from your projects and share them on GitHub.We will use it later to learn how to solve merge conflicts.
Now the new file is tracked by Git and is added to the Changes changelist in the Commit tool window Alt+0.

The Changes changelist helps you manage local changes that have not yet been committed to a Git repository. Learn more in Group changes into changelists.
There is also the Unversioned Files changelist with the list of files that belong to your project but are not yet added to the Git repository. We will not work with them in this tutorial, but you can always learn more about unversioned files in Exclude files from version control (ignore).
Step 3. Commit your project to the local Git repository
Now let's add all the files you want to share to the repository and commit them to save their current state.
In the Commit tool window Alt+0, select the files you want to commit by clicking the checkboxes next to them.
Type a message for your first commit:

Click Commit. MPS notifies you after a successful commit:

If you have not used Git on your computer, right before committing your changes MPS will ask you to enter your username and your email. Git will store this information in
.git/configin order to assign you as an author to your commits.
Step 4. Share your project on GitHub
To make your project available for other contributors, you need to publish it to a remote repository, for example, on GitHub or on GitLab. MPS provides integration with both these platforms. Learn more details in Manage projects hosted on GitHub and Manage projects hosted on GitLab.
In this tutorial, we will publish our project on GitHub.
In the main menu, go to .
In the dialog that opens, you can change the repository name (by default, it is the same as the project name), the name of a remote (by default, origin), choose the repository type (public or private), and add some description if needed.
If you are not registered on GitHub, click Add account and then Log In via GitHub.

Enter your GitHub credentials in the browser window that opens or create a new account there. When you go back to MPS, the Share by field will show your account's name.
Click Share. After the project is successfully published on GitHub, the following notification will appear:

Click the link in the notification to open the repository on GitHub.
Step 5. Create a new branch
You may need to create a separate branch, for example, when you are working on a new feature and you don't want your changes to get into the main branch before they are tested.
Press Ctrl+T to pull the latest version of the current branch.
In the dialog that opens, specify the branch name, for example,
new_feature, and select the Checkout branch checkbox to switch to the new branch right away.
Now you are switched to the newly created branch:

Step 6. Make and view the changes
Add a new file to the project (for example,
git-features.md) and click Add when MPS suggests adding it to Git version control.After that, open the
README.mdfile and replace the existing text with the new description:#Demo This is a demo project where you will learn how to commit and push changes, create and merge branches. Refer to `git-features.md` to check the list of Git operations.In the Project tool window Alt+1 and in the editor tabs, MPS applies different colors to files: blue to modified, green — to newly added. Moreover, in the gutter area of a modified file, the colored change markers appear next to the modified lines.

To review what exactly was changed, click the gutter marker:

To view the difference in a separate editor tab, click
:

Go to the Commit tool window Alt+0, to preview all the changes at once. Double-click a file to open the diff view in the editor:

Learn more in Investigate changes in Git repository.
Step 7. Commit and push the changes
In our new_feature branch, we have created a new git-features.md file and have modified the README.md file. Let's commit our changes and push them to the remote repository.
In the Commit tool window Alt+0, select the checkboxes next to both our files, and type the commit message (for example,
Update README.md).When typing the commit message, you can use auto-completion for the project file names Ctrl+Space:

Click Commit.
Press Ctrl+Shift+K or select from the main menu to push the changes to the remote repository. The Push Commits dialog opens. Here you can review all the commits to be pushed as well as all the affected files. Before pushing the changes, you can review the differences for each file. To do this, right-click a file and select Show Diff or press Ctrl+D:

Click Push.
Step 8. Merge branches and resolve conflicts
There are several ways how you can apply the changes from one branch to another, such as merging and rebasing the branches, cherry-picking commits, applying separate changes or files. All these methods are described in detail in Merge, rebase, or cherry-pick to apply changes.
In this tutorial, you will learn how to merge two branches. We will also make a merge conflict on purpose to learn how to easily resolve merge conflicts using MPS's merge tool.
Merge branches
Select the
mainbranch in the Git Branches popup and click Checkout.In step 6, we have modified the
README.mdfile in ournew_featurebranch. Now let's update the text one more time in themainbranch to simulate a merge conflict, for example:#Tutorial This is a test project where you will learn how to work with the most popular Git operations.Commit and push the change as described in step 7.
In the Local node of the Git Branches popup, select
new_featureand click Merge 'new_feature' into 'main'.
Since we have made changes for the same file in different branches, the Conflicts dialog appears.

Resolve conflicts
In the Conflicts dialog, you have several options to resolve the conflict:
Accept Yours to keep the changes made in the current branch.
Accept Theirs to apply the changes from the branch that you want to merge into the current one.
Merge to resolve conflicts manually in a dedicated dialog.
Click Merge. The Merge Revisions dialog opens:

The left pane called Changes from main shows the read-only changes from the local copy.
The right pane called Changes from new_feature shows the read-only incoming changes from the
new_featurebranch that we want to merge tomain.The central pane called Result is a fully-functional editor with the results of resolving conflicts.
In this dialog, you can accept changes by clicking
/
, decline them by clicking
, and type code in the Result pane in the middle. Learn more in Resolve Git conflicts.
Let's accept one change from
mainfrom the left pane by clicking. As we do not need the changes for the same line that come from
new_feature, clickin the right pane in the red conflicting line to discard them.
Click
on the right pane for the remaining non-conflicting changes that come from
new_feature.Review merge results in the central pane. The merged text should look like this:
#Demo This is a test project where you will learn how to work with the most popular Git operations. Refer to `git-features.md` to check the list of Git operations.
Click Apply.
Push the changes to the remote repository by pressing Ctrl+Shift+K or selecting from the main menu.
You can review the commits in all the branches in the Log tab of the Git tool window Alt+9:

From here, you can also revert commits, cherry-pick changes from one branch to another, and more. Refer to Log tab for more details.
Step 9. View history
When you work on a project with other people, you may have questions like why, when, and how this file was changed.
In the main branch, open the README.md file. To find out in which commit these changes came from, do one of the following:
Right-click the file in the editor or in the Project tool window Alt+1 and select . The History tab of the Git tool window opens:

On this tab, you can view all commits that affected the file and find out in which commit the change of your interest was added.
In the editor, select a code fragment you want to view history for, right-click the selection, and choose . The History for Selection window will open:

Here you can review all the commits that affected the code selection of your interest.
Find more ways of exploring the Git history in Investigate changes in Git repository.
What's next
If you didn't find how to perform some specific Git task in this tutorial, refer to the Git guidelines — all the Git operations available from the IDE are described there.
If your project is not under Git, you can still track and manage local changes, roll back to the specific file state, restore deleted files, and more using the Local History feature.
