Advanced Git

This documentation is for Dash Enterprise,
Plotly’s commercial platform for managing and improving
Dash applications in your organization.
View the docs or
request a trial.


Plotly uses Git to manage Dash App deployments.
This section serves as a reference for what git commands are utilized,
when to use them, and why.

 

  • Initialize a Repository
  • Cloning a Repository
  • Remote Repositories
  • Deploying Changes
  • Using Branches

Initialize a Repository

If you have created a new folder for your Dash App, or have an existing
folder on your local machine, you need to initialize a local Git
repository before you can deploy your Dash App to the Dash Enterprise.
You need to initialize the local Git repository from your app’s
root folder, thus:

$ cd myDashApp
$ git init
Initialized empty Git repository in .git/

Cloning a Repository

If you have an existing repository hosted on Github, or would like to
utilize one the demo Dash Apps from Plotly’s Gallery, then you
you’ll need to clone the repository. You can achieve this by using the
git clone command:

$ git clone <respository-name>

 

Note: the above command will generate a local Git repository on your
machine, which by default will include the remote Github repository
origin. If you’re concerned that you may accidently push to this
repository, you can remove it. See the next section Remote Repositories
for how to view and remove remote repositories.


Remote Repositories

Once you have initialized your local Git repository or cloned an existing
repository from Github, you need to create a remote repository on the
Dash Enterprise, which you will deploy your changes to.
Note that this remote repository will be your live / production Dash App.

 

To create a remote repository

$ git remote add <remote-name> <remote-URL>

 

To view all remotes:

$ git remote -v

 

To rename a remote repository:

$ git remote rename <existing-name> <new-name>

 

To remove a remote repository:

$ git remote rm <remote-name>

Deploying Changes

By default, Dash apps run on localhost - you can only access them on
your local machine. To share a Dash app, you need to “deploy” your Dash app
to the Dash Enterprise platform. This can be achieved via a series of
commands. Namely,

  • git status allows you to view which files have been changed.
  • git diff prints out changes within the files.
  • git add . will add all your changes.
  • git commit -m "a description of the changes" will commit you changes.
  • git push <repository-name> master will deploy your code to
    Dash Enterprise.

 

git status and git diff are optional and are only required if you
wish to inspect before adding changes.

 

The demonstration below is a common way to deploy your changes:

$ git add .
$ git commit -m "a description of the changes"
$ git push <respository-name> master

Using Branches

If you want to try out a new feature or test something different with your
Dash App but don’t want to alter your master code, you can create a
branch to encapsulate these changes.

 

To view all branches:

$ git branch

 

To create a new branch:

$ git branch <branchname>

 

Once you’ve created a new branch, you need to check it out (i.e. navigate
to it).

$ git checkout <branchname>

 

If you have created a new branch and are happy with the changes, you can
add and commit these changes using the common git add . and
git commit -m "description" commands. To deploy these to Dash Enterprise,
you will need to deploy the branch into master:

```shell
$ git add .
$ git commit -m “a description of changes”
$ git push <remote-name> <branchname>:master

 

To rename a branch:

$ git branch -m &lt;existing-name&gt; &lt;new-name&gt;

 

If you no longer require the branch, you can remove a branch:

$ git branch -D &lt;branch-name&gt;

 

Note: using -D will delete the branch and all unmerged changes.


Additional Resources

For more information regarding version control and Git commands, see Git’s
documentation.