Plastic SCM is a full-featured DVCS (Distributed Version Control Software). And, Plastic SCM also speaks the Git network protocol.
Plastic SCM can push and pull changes directly to any remote Git server. This is because Plastic supports the https:// and git:// protocols for pushing and pulling changesets.
This feature immediately turns Plastic SCM into a DVCS fully compatible with Git. The advantage of this is that you can use Plastic or Git on your workstation and still participate in Git projects (GitHub, CodePlex, and many more).
This can be a first approach: GitSync is a native Windows DVCS connected to GitHub. So, it virtually turns Plastic SCM into a full-fledged Windows client for Git.
Imagine that you're a developer using GitHub (or Bitbucket, or maybe CodePlex). In any case, there are things you like: using a cloud-based repository for your code and Windows to develop. And things you don't like: being forced to use the CLI and lacking really awesome GUI tools.
So, you wish you had everything: Cloud repositories, the DVCS power, and awesome tools for Windows.
That's what you get with GitSync.
The capabilities of GitSync are:
An entire push and pull process will show you GitSync works.
You have a Git repo, and you pull it on Plastic. As a result, you get an exact clone with the branches and commits you had in Git now converted to Plastic, and what's best about this is Plastic SCM is able to render those branches and commits in the Branch Explorer:
The following image shows what happens when a new commit is created on the Git side and how the pull from Plastic SCM retrieves it.
Instead of just performing a simple change, the figure shows a merge from big_feature branch into master. The result in Plastic SCM mimics what happened at the Git side, adding the merge link (which is rendered as a green line) on the Plastic Branch Explorer:
The next step is performing a change in Plastic SCM and pushing the change to Git. To create a more complete example, a merge will also be made instead of just creating a new changeset.
The changesets 6 and 7 are created on the Plastic side, then they're pushed to Git. As you can see in the figure below, the merge information (multiple parents on the Git repo) is also sent from Plastic to Git.
So far, the changes were done at one side or the other, but not at the two sides concurrently.
The following picture shows what happens when developers work on the same branch at the same time. A new commit is created in Git (on green) and another in Plastic (orange):
If the Plastic developer tries to push to Git, an error will show up since there are conflicting changes (which would happen on a similar scenario on a pure Plastic or pure Git setup). The steps to follow are:
Both repositories will look the same at the end of the interaction and let developers work together on both sides.
The GitSync configuration file (gitsync.conf
) lets you include information automatically used during the GitSync operations.
This information is related to the mapping between two Plastic SCM and Git objects:
gitsync.conf
file must be located in:
plastic4
directory (under $HOME/.plastic4
on Linux/Mac systems or C:\Users\user\AppData\Local\plastic4
on Windows).
In the gitsync.conf
file, we can define a mapping between Plastic and Git (emails). This information will be used as author and committer when committing to Git.
This info is added on the email-mapping
section in the following format:
plastic_user = git_email_address
An example of gitsync.conf
file:
[email-mapping] asalim = asalim@mymailprovider.com ubuntu = ubuntu@linuxprovider.com
A Git submodule is just a pointer to a commit in a different repository. It doesn't propagate operations between submodules or handle the branching between the repositories, so this very basic information is enough for the submodules work.
A Plastic Xlink object is more complex than the Git submodule: the Xlinks allow the user to set relative servers, set rules for the branch expansion, and define whether the Xlink is writable or not.
In general terms, we can say that Git submodules and Plastic Xlinks have the same mission: pointing to a commit in a different repository. So a direct mapping can be established between:
GitSync lets you create Plastic Xlinks from Git submodules and vice versa. The Git submodules and the Plastic Xlinks can be synchronized using GitSync:
Before synchronizing a repository with Xlinks/Submodules, the target repositories must be synchronized.
To synchronize a repository with Xlinks/Submodules, the mapping information must be added on the gitsync.conf
file. This info is added on the submodules section with the following format:
git_repository_url -> plastic_repository_spec [writable:true|false] [relativeserver:true|false]
writable
field must be included as writable:true
. If the writable
field is omitted or set to false, the Xlink is created as read only.relativeserver
must be included as relativeserver:true
. If the relativeserver
field is omitted or it is set to false, then the Xlink is created against the Plastic repository server (as non-relative Xlink).This would be a valid configuration example:
[submodules] git://localhost/code -> code@localhost:8084 writable:true relativeserver:true git://localhost/doc -> doc@localhost:8084 writable:false relativeserver:true
Two Git operations are restricted when using GitSync:
rebase
commandmerge
(fast-forward) commandThese Git commands don't take into account the history of your changes. Although the user can work in a parallel way, Git talks about history like something linear. But Plastic prioritizes keeping the changes history.
Plastic SCM takes into account the whole history of the changes you make. This means that Plastic doesn't rewrite history (a design decision).
The changes history is reflected when working on branches and merging. Because Plastic SCM can solve and show how the history is, we recommend you avoid using those Git commands when working with GitSync.
Plastic has the Branch Explorer, which lets you understand what is going on graphically. This way, you are not distracted and you don't miss rebasing.
When you diff a branch with several merges, it is hard to see what you really changed on the branch and what comes from the merge... this is also solved in Plastic:
As we've seen previously, Plastic can push and pull directly to remote Git servers using both native Git and HTTPS protocols, including well-known sites such as GitHub, BitKeeper, CodePlex, and many more.
When we started developing the Git-bidirectional synchronization with Plastic SCM, we had the following scenarios in mind:
We went the hard way for a solution: we didn't come up with some sort of intermediate script to convert changes from one system to the other or do fast-import/export, imposing a ton of limitations. But we actually implemented was the Git network protocols in Plastic as a layer able to directly pull and push to Git.
Plastic starts a negotiation phase with the remote Git server, as a Git command would do, speaking the Git protocol. It is a core feature, not an add-on script.
As we've said, GitSync implements the smart-protocol and:
Let's start by connecting to a GitHub repository.
Now, to pull it to Plastic, a repo is created to "host it" (called corefx too) and in the initially empty Branch Explorer, the context menu option to launch Sync with Git:
No need for credentials now since we're just pulling (cloning) from a public repo. You'll need to specify them if you need to push, and the server requires you to be an authenticated user.
Note: If you use Github and need authentication, you must use a token and not a password. For more information, see Creating a personal access token
Assuming the local corefx repo is empty, it will calculate the changesets and branches it needs to pull from the remote GitHub repo and will pull them:
To pull new changes done on the GitHub side, simply re-run the same command:
cm sync corefx git https://github.com/corefx/corefx.gitAnd it will now calculate and pull only the new changes made on the Git side if any.
You're currently pulling Git changesets and branches directly to your local Plastic SCM repository:
And now, right-clicking any changeset (commit in Git jargon), you'll be able to check differences with our built-in diff system:
Now you're ready to do more changes in Plastic, whether branches, merges, anything. Then repeat the same process to sync to Git (which will in turn push or pull changes and even ask you to solve merges before pushing back to Git if concurrent changes were done on the same branches).
We're going to push one of our Plastic repositories to GitHub. This process is similar to the previous one.
The Sync dialog will be launched.
We're currently pushing Plastic SCM changesets and branches directly to my GitHub repository.
Assuming the GitHub dokancode repo is empty, GitSync will calculate the changesets and branches it needs to push from the Plastic repo, and will push them:
Once the push operation is finished, you can see a summary of the objects that have been exporting:
Now you're ready to work with the repository in both sides: Plastic SCM and GitHub. You'll be able to create branches, do changes, and synchronize again by pulling/pushing.
In this section, you'll learn how to work with the dokancode repo, in the GitHub and Plastic sides, applying some basic operations.
As an example, some operations will be run on the master branch:
The commits are done, and you can see them on the Plastic side.
GitSync can calculate what's new on the other side, negotiate with the remote server, and push the changes.
Once the synchronization is complete:
Now you can continue performing changes on Plastic.
As an example, changes are made to the scm005 branch. At this point, both the Git and Plastic have the same content. You can check it on both sides:
In this branch:
These are the new changes:
The summary tells you that the synchronization has sent two changesets involved in one branch:
Note that the Plastic main branch is mapped to the Git master branch. This mapping is also considered for the children branches of main on Plastic. This means that the Plastic branches are converted into Git branches by removing the hierarchy and replacing the / with -. And this rule is also valid when a Git branch is converted into a Plastic branch: the - character is used to recreate the hierarchy in Plastic.
In the examples before, the Plastic branch /main/scm005 is converted to master-scm005. And the Git branch scm007 under master is converted to /main/scm007:
The - character is also allowed as part of the branch name like the following examples:
Branch - Git side | Branch - Plastic side |
---|---|
master | /main |
master-fix-5.0 | /main/fix-5.0 |
master-fix-5.0-task1 | /main/fix-5.0/task1 |
Since Plastic SCM handles the same concepts as Git (DAG, commits, merge links, and so on), it is straightforward to share the merge tracking. You do a merge in Git, you can get it back to Plastic. If you do a merge in Plastic, you can even push the merge link back to Git.
The most difficult feature for us to handle is the "precise item tracking"; we do (and Git doesn't). Plastic has an internal id associated with each file and directory. It means we can easily handle tons of merge conflicts that are hard to track for Git (like a divergent move, something trivial for Plastic).
In the following examples, you'll see how the merge tracking works when using GitSync.
In the following example, two branches are created:
The new branches have been pushed and the merge tracking looks like this on Git:
Now we're going to see how a merge in Git is tracked on Plastic.
The merge is complete, and these changes have to be pulled to the remote Git repo:
As seen in the How it works section, you can make changes concurrently both in Plastic and Git. This means that you can work on the same branch on the two systems and reconcile changes (as you do when using a pure Plastic or Git environment).
In the Changes on the Git side section, some changes were made on GitHub:
Now, to perform some changes in Plastic:
Once the changes are done, synchronize both repos using Sync with Git:
When the synchronization is finished, a message will pop up saying a merge is needed.
This is because we made some changes in the same branch in Git and Plastic.
In the summary, you'll see that the main (or master) branch is the one that requires a merge operation:
Changes were made in the master branch in Git, and some other changes in the main branch on the Plastic side. Remember, that main and master is the same branch but using different names (see the Git-Plastic Dictionary for further information).
As seen in the How it works section, you have to resolve the merge conflict at the Plastic side.
The changes that are going to be merged:
Once this operation is finished, both repos are fully synchronized. This means that you have the same content on both sides.
GitSync supports sync with Git repositories using the SSH protocol.
The SSH protocol lets you connect and authenticate to remote servers and services.
To use this feature:
The SSH agent now manages your SSH keys and remembers your passphrase.
You can use GitSync the same way as you usually do with HTTP protocol, by using the Plastic GUI or the CLI.
Let's see an example. If you use the command line, you have to specify the URL accordingly for the SSH protocol:
$ cm sync rep2 git git@github.com:PlasticSCM/Myrepo.gitinstead of the HTTPS one:
$ cm sync rep2 git https://github.com/PlasticSCM/Myrepo.git