How sync your salesforce code to Github/bitbucket?

Learning Code version Management and Control.
How sync your salesforce code to Github/bitbucket?

Situation

Version control, for most developers, is an absolute must in any professional setting. However, currently, in salesforce org, there dont have Code version Management/Control.
One solution is using plug-in(Subversion) for Eclipse, but it need the deveploer to install Eclipse in their local machine.

Solution

Today, I will introduce one solution which is using unix+ nodejs to retrieve salesforce code and then push the code to Githut/Bitbucket.

Method

Firstly, I will setup my linux workspace, there, I use cloud9. Also, you can use your local machine.

Secondly, I will retrieve all code-related metadata in salesforce, this include lightning component, apex Component/Visual force page, class. and tigger .

Thirdly, I will push all related code to the Githut/Bitbucket.

All above steps will be like following.

alt tag

retrieve all Code-Related Metadata

There, I use JSForce library to retrieve all Code-Related Metadata and object matadata.
Also you need to install related library in your machine

  • npm install jsforce
  • npm install js-beautify
  • npm install mkdirp

The related code:

Cloning Repository and push the code to the Repository using shell script

Firstly, I create shell script file named ‘Gitshell.sh’, I the shell script file, I will do following things:

  • create one foler name ‘backup’.
  • Clone my Repository from Githut/Bitbucket in ‘backup’ foler.
  • Retrieve salesforce code from Sandbox/Production using nodejs JSForce.
  • Move the Retrieved code to the cloned Repository folder.
  • Push all related the changes to Githut/Bitbucket.

The related code:

You can run ‘bash Gitshell.sh’ Linux Terminal