Using Git as part of your workflow on Pagoda Box can be somewhat daunting if you've never used Git before or feel out of your element working from a command line. This guide is meant to walk you through the basics of the Git + Pagoda Box workflow. After reading it, you will be able to:
- Confidently update and manage your application on Pagoda Box using Git
Setting Up Git
Git is an extremely fast and efficient code version control system that allows you to easily collaborate on and manage your application codebase. There is somewhat of a learning curve, but once you get the hang of it, it'll be hard to go back to how you worked before. If you haven't set up git, you'll need to do that. Our Setting up Git Guide with walk you through the process.
Getting Your Code to Pagoda Box
Whenever you launch an app on Pagoda Box, you're given a few terminal commands that will get your code from your local desktop onto Pagoda Box.
Before you run any of these commands, you'll want to navigate to the root directory of your codebase in your Command Line Client. This is done using the "cd filepath" command.
TerminalInitializing an Empty Git Repo
This command initializes an empty git repository using the directory you're currently in. You then need to add the contents of that directory (your codebase) to your empty git repo using the following command:
TerminalAdding Code to Your Repo
Once your code has been added to your repo, you then need to "commit" those changes. Committing is basically staging code to be pushed. If code is not committed, it will not be pushed. It's a good idea to include a commit message with each commit explaining what changes have been made. Commit messages in your git history allow you to quickly diagnose and fix any issues that may arise in the development process.
TerminalCommitting Your Code
Once you have code committed and ready to push to Pagoda Box, you need to add a "pagoda" remote. A remote is basically The name of the remote does not have to be "pagoda," but all other references in our guides refer to your pagoda remote.
TerminalAdding a Pagoda Remote
With the git remote add command, you specify the remote name (pagoda) and the git clone url of your new remote (git@git.pagodabox.com:your-app.git). After adding your pagoda remote, you're ready to push your app to Pagoda Box.
TerminalPushing Your Code to Pagoda Box
The git push command pushes all of your committed code. Specifying the pagoda remote will push your code to Pagoda box. And adding the --all parameter will push all of your git branches to Pagoda Box. If you only want to push a specific branch, replace --all with the name of branch you want to push.
Congratulations! You've successfully deployed your app to Pagoda Box using Git.
The Basic Git + Pagoda Box Workflow
The life of an app usually consists of repeating the simple process of making code changes locally and pushing them live. This is where Git makes life really easy. When ever you make any changes in your repository and you want to add those changes, simply run this command:
TerminalAdding Code Changes to Your Repo
Then commit your changes with a message describing what changes were made:
TerminalCommitting Your Changes
If part of the changes to your repo was deleting files, you will need to include the -a parameter in your commit command to actually remove those files from your repo on Pagoda Box. If the -a parameter isn't included, the files you deleted will only be removed from your local repo and not from your Pagoda Box repo.
TerminalCommitting the Deletion of Files
Once you've committed your code, go ahead and push it to your pagoda remote:
TerminalPushing Changes to Pagoda Box
You can also specify a branch to push to pagoda or push all branches:
TerminalPushing Branches to Pagoda Box
Once you push your code to Pagoda Box, it will automatically be deployed, unless you have auto-deploys turned off. If you have auto-deploys turned off, you can deploy your code manually by clicking the Deploy Latest button in your app dashboard.
Adding Collaboration to Your Workflow
When collaborating using git, there's really only one basic command you need to add to your workflow: git pull. There is a lot more collaborative functionality built into Git, but for simplicity's sake, well just worry about this one.
When a collaborator pushes code changes to your repo on Pagoda Box, you need to merge those changes into your local repo. This is done using the git pull command:
TerminalPulling Code Changes from Pagoda Box
On occasion, changes that collaborators have made may conflict with with changes you've made. Git will allow you to resolve those conflicts, but that process is beyond the scope of this guide. You can learn everything there is to know about Git through a little further reading:
Further Reading
The commands and steps that we've discussed are just the basics of Git and should fit most of your workflow scenarios. However, Git can allow you to do many more things. If you want to learn more about git, Scott Chacon has written great book that walks you through Git step by step. It's free and is called Pro Git.
Table of Contents
Setting Up Git
Getting Your Code to Pagoda Box
- Initializing an Empty Git Repo
- Adding Code to Your Repo
- Committing Your Code
- Adding a Pagoda Remote
- Pushing Your Code to Pagoda Box
The Basic Git + Pagoda Box Workflow
- Adding Code Changes to Your Repo
- Committing Your Changes
- Committing the Deletion of Files
- Pushing Changes to Pagoda Box
- Pushing Branches to Pagoda Box
- Adding Collaboration to Your Workflow
- Pulling Code Changes from Pagoda Box