Setting up a version control system

If you are familiar with maintaining projects remotely with version control systems such as Git or SVN, then you can skip this section. Version control systems make it easier to keep track of changes and also push and pull new versions of code from a remote repository. If you haven't already, install Git from https://git-scm.com/
Create a project folder and create a new Git repository inside your project folder (use the Terminal application for Mac and Linux or the Git bash program on Windows). The project folder will look like the one we made on our Raspberry Pi:

mkdir sensor-project
mkdir sensor-project/hello-world
touch sensor-project/hello-world/hello-world.js
cd sensor-project
git init

Add all your files to the repository and make a commit:

# Add all files to staging area
git add -A

# Commit to repository. Mark the commit with a message
git commit -m "Initialized first project"

Next, create a remote repository on a site such as GitHub (https://github.com/) or Bitbucket (https://bitbucket.org/)

You will get a remote URL (we can use https://my-remote-repo-url.com/sensor-project.git for the purpose of this section):

# Add the remote link
git remote add origin https://my-remote-repo-url.com/sensor-project.git

# Push all changes to the remote repo
git push origin master

Now, all your code is present on the cloud. All you have to do now is go into your Raspberry Pi's Terminal and run this:

git clone https://my-remote-repo-url.com/sensor-project.git
cd ~/sensor-project

You now have the project fully cloned on your Pi. To make changes and reflect them on your Pi, first, make the changes to files or folders on your computer and then add and push the changes to the repository:

# Run these commands after making changes to code files
git add -A
git commit -m "Made some changes"
git push origin master

Then on your Pi, run this:

cd ~/sensor-project
git pull origin master

You now have version control set up and can easily push code from your machine to your Pi.

The next time I mention "syncing code to the Pi" or "pushing code to the Pi", this pushing and pulling of code is what I'm referring to. If you are writing code directly on the Pi, you don't have to do this.

An interesting point to note is that since Git is decentralized, this process can also be done the other way round, which means that if you make any changes to the code on the Raspberry Pi and not on your local machine, you can push the code from your Pi and then pull it from your computer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.141.202