Starting off a python data science project on GitHub

Automatize repository creation and the set up of your work environment with this simple bash script

Fernando Costa
4 min readSep 9, 2020
Photo by Clément H on Unsplash

edit: this method is now deprecated by github

So you want to start working on a project and write some code, but you first need to get all the things up and running: the code editor, the git files, maybe the jupyter notebook…a bunch of things that take a few minutes and of which you will likely forget some.

So let’s begin! You will need to have your repository both locally and remotely. To do so, there are two main ways to do it: using terminal (command line)+ GitHub web & just using the terminal (bash script).

⚠️ Both of these ways work, however, if you’re starting to code I would definitely recommend to use the first script (command line) only as a checklist and write all the commands manually so that you get used to bash & git and practice.

The second one (automated) is easier to deal with and way more comfortable, but it only makes sense for you to use it if you already learned the previous steps.

Terminal + Github

  1. Create a LOCAL repository
mkdir NAME_OF_THE_REPO
cd NAME_OF_THE_REPO
git init
touch README.md
touch requirements.txt
echo ".ipynb_checkpoints
*/.ipynb_checkpoints/*
**/.DS_Store" > .gitignore
touch main.py

2. Create a REMOTE repository

Go to GitHub, create a repo and copy the clone link.

I mean, yes, you could also create the remote repository and then do git clone, but do you really want to miss on all the fun of using the command line?

3. LINK the local repo to the remote one

git commit -am "commit zero"
git branch -M master
git remote add origin <https://github.com/YOUR_GITHUB_USERNAME/NAME_OF_THE_REPO.git>
git push -u origin master
git add .
git status

4. Setting up the work ENVIRONMENT: VSC, Finder, Jupyter & iTerm

code .
open .
jupyter-notebook
open <http://localhost:8888>

Here’s the link to the gist in case you find it more useful.

❗️This is thought to be used on MacOS & iTerm2. Things like the “.DS_Store” files or commands like open . won’t work or make sense if you’re using a different system.

Just Terminal (iTerm2)

Create a new script:

touch repo.sh

and add the following code:

If you still don’t want to make your repo public, you can set the parameter on line 4 to true.

Then run it passing two arguments: your GitHub username & how you want to name your repo:

bash repo.sh your_github_username new_repo

A bunch of windows will open at once and it’ll go berzerk for half a second. Don’t worry, it is expected.

Nico De Pasquale Photography/Getty Images

So all of this works, but why? Let’s try to break it down:

Git

  • curl: “command line tool to transfer data to or from a server, using any of the supported protocols (e.g. HTTP)”
  • $1, $2: variables to pass when running the bash script
  • git init, clone, add, commit, push, status (more here)
  • git branch -M master: it declares which will be the Main/Master branch
  • git remote add origin [link]: it links the local repo to the remote one, so when you push on Git, it actually uploads the changes to Github

Flags:

  • -u: user
  • -d: data sent through an API
  • git commit -a (all the files) -m (using the message as the commit name)

Bash/iTerm2

  • mkdir: make directory
  • cd: changes directory
  • touch: creates a new file
  • open .: opens finder in the present working directory
  • code .: opens VSC in the pwd
  • mv: moves a file to a different directory

Now you just need to create a new jupyter notebook. With all the files and software ready to go, you can just start writing code! 🚀

To finish your project, do NOT forget about two things: README.md & requirements.txt

1️⃣ The README might be one of the most important parts of your project. When looking at a repository, there’s a ton of folders and files and it’s very useful to provide with a short insight of what the project is for. It can make a difference from your work been seen or not.

For this, I would recommend becoming familiarized with Markdown and maybe create a template, so that it’s easier for every upcoming project.

2️⃣ For the requirements.txt:

pip3 install pipreqs

then:

pipreqs

et voilà! 👌

--

--