Automatically push Salesforce METADATA to GIT

191 Views

This is going the be a very important post as using this batch and bash file, you can do automate backing up your metadata on GIT version control.

What is Git?

So, what is Git in a nutshell? This is an important section to absorb because if you understand what Git is and the fundamentals of how it works, then using Git effectively will probably be much easier for you. As you learn Git, try to clear your mind of the things you may know about other VCSs, such as CVS, Subversion or Perforce — doing so will help you avoid subtle confusion when using the tool. Even though Git’s user interface is fairly similar to these other VCSs, Git stores and thinks about information in a very different way, and understanding these differences will help you avoid becoming confused while using it.

What is GIT?. Git is a version control system. | by Smile2gether | Medium

You can choose which platform you’re going to use for manage your code it could be GITHUB, GITLAB and etc.

GitHub vs Git vs GitLab vs Bitbucket | Comparison

I find GITLAB better and cheap so you’ll find the example below more related to gitlab but you can simply replace gitlab urls to Github or anyother platform you’re using.

You don’t need to know much about CLIs but a little knowledge is required.

Pre-Requisite

There are many tools available online which provides command-based easy way to fetch and push your metadata. I found JSFORCE easy so here is the url plus how you can install.

First, download and install NODEJS : https://nodejs.org/en/

Second, Download and install GIT: https://git-scm.com/downloads

then, Open CMD and paste this command.

npm install jsforce-metadata-tools -g

Now you’ve JSFORCE installed on your Machine.

PACKAGE.XML GENERATION

There are many tools online available from where you can generate package.xml like vscode plugin, SF Workspace or Salesforce package.xml Builder. I personally like this heroku tool which is online and can generate the file within minutes.

Go to : https://packagebuilder.herokuapp.com/ and generate your package.xml file and store it some where.

this is very important step and using this xml file, we’re going to fetch metadata from the org, either its Production or Sandbox.

Final Step

Now, use this BATCH (for windows right now) file to schedule your automation.

But before, make sure you init the git using the following commands,

> git init
> git remote add origin https://<username>:<password>@<gitlab-url.git>

Make sure you modify the file and replace the steps.

Hurray! Now you’ve automated backup with version controlling setup ready.

Leave a Comment