MPLAB X includes great built-in support for Git but it assumes projects are created first from within MPLAB X (File > New Project ) before managing them using Git. If you’re starting by cloning a remote repo, the simplest way is using a stand-alone Git client.
Everyone has their own favorite Git client, but in order to keep things simple for the team we’ll use the standard Git install for Windows from the Git project to clone the remote repo, and use MPLAB X’s built-in Git features for everything else.
The Git install includes Git GUI, a GUI applet for creating and cloning repositories, and a command line terminal for everything else. However we won’t have to worry about learning command line Git operation as we will be using the Git features in MPLAB X for day-to-day use.
Start the Git GUI applet,
and select Clone Existing Repository.
Clone the remote master repository locally (the master repo for me is on a Windows network drive).
When the remote repo has been cloned, Git GUI will show the current status of the new local repository – which should show no modified files (i.e. no files either staged or unstaged).
To confirm the repository was cloned correctly, you can check the commit history by accessing menu Repository > Visualize master’s History.
Now we can open the cloned local repo using MPLAB X.
Git is primarily accessed using a project’s context menu from the Project window.
However, be aware there are a few Git commands under the Team menu, including a Repository Browser that isn’t available from the project context menu.
Try accessing Show History for the project (you will need to click “Search” in the Show History view that opens).
Now I’ll ready to start hacking on the source. I’ll keep it simple and just add some TODO’s to the README.txt file. Notice how the editor shows my changes compared to the last commit in real-time!
When I’m ready to commit my changes, I can commit just the modified README.txt file,
or I can commit all modified files in the project.
To push a local commit back to the upstream origin repo, use the general-purpose Remote > Push… selection from the Project context menu.
Origin is the only remote repo configured in the local clone, so it should be indicated automatically in the Push to Remote Repository wizard.
There, all done! Wasn’t that easy?
I didn’t do show it here, but standard practice is to always Pull from the upstream repo (e.g. origin) before you try pushing code. If someone has pushed code to the master repo since your last pull (or clone), you’ll need to merge their changes from the master repo into your local repo first, then push your combined changes back to the upstream repo.