Salesforce with SourceTree

In my previous post about Git, we talked about handling metadata in a local copy using git CLI and GUI. Today, I am going to talk about Salesforce with SourceTree. SourceTree is a free tool.SourceTree simplifies how you interact with your Git and Mercurial repositories so you can focus on coding. If you have not gone through the previous post related to this have a look at the below post:

https://getthekt.com/2017/03/git-with-salesforce-locally/

We are still discussing about a local copy. In near future will show how to deal with a remote git server as well.

If you already do not have a copy of sourcetree. Get it from the SourceTree site.

SourceTree Window

Sourcetree window

Here is a typical sourcetree window you can find.

Create a New Repository

You will find a Clone/New button at the top left corner of the window. Once you click on that you can “Clone Repository” , “Add Working Copy”, “Create New Repository”.

If you select Clone Repository you can configure and pull remote repository:
cone repository

Add Working copy will give you option to open any existing repository you might have locally. In this article we will use this option. As soon as we select the existing repository the sourcetree will detect the kind of repository we selected. In this case you will notice the repo i selected is a Git repo and has been identified by the sourcetree.

Add working copy

Create New Repository will give you options to create a new repository for git pr mercurial (Another versioning system).
create new repo

Once the repository is added you will see all the details in that repository. Such as commits and branches etc.

added repository

At this point I have a master branch. That’s the selected branch at this time.

Creating a child branch

Click on the Git flow menu at the right top corner. This will initiate the git flows for the repository. You can create developer branch, hotfix , feature branch etc afterwards. At this screen you can make changes as per your needs or keep it default. Once you click ok on this window, you might see a developer branch already created for you.

git flow menu

develop branch

You can select the develop branch. if not already selected, by double clicking on the branch. Click on Git flow icon and you will see a similar option as below:

start new feature

In this case I will show how to start a feature and merge that to the parent when ready.

new feature

Now we can make changes to our component for this feature. For now I will make changes to the trigger I used in my previous post. Will add a new comment line. This should show up in the sourcetree window. Click on the uncommitted changes and you can see what all changes are added after the last commit.

uncommited changes

changed lines

Click on the commit button at the top left corner and you can enter you commit statement and done. As of now let’s assume we are done developing this feature and we can merge the code to parent branch and delete the feature branch.

commited the lines

merging the feature to develop branch

select feature to merge

Right click on the feature and click on delete feature once the feature is merged into parent branch. You will see the changes made as part of feature is already in the develop branch after the merge.

delete feature

Similarly you can delete develop as well once the changes are merged to the master if you want. You can see the changes made for a feature is present in the master now and we are ready to start a new feature or branch from the master.

deleted develop

Conclusion

Hope this post can help someone out there, who needs it, to start with the code versioning. As I said in the previous post, having your own code versions might save you a lot of time and headache sometimes.

Keep reading and sharing ….


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *