My Git & conda cheat sheet 🚀
Update: Added a tip for installing Python on your machine for the first time. It might seem very easy, but if someone is just starting to learn programming, this will be very useful.
Install python in your environment
conda install python=3.x (version you want)
If you don’t know what version of Python you have installed on your computer, you can always type the following in the terminal:
python --version
For install Pip you only write a few lines
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
Use a conda environment in a Jupyter notebook
A great trick is to be able to use your own environments with all their libraries in a Jupyter environment. I learned this from two great teachers at Ironhack (David and Pedro).
Under these lines you have the step by step to create a virtual environment to work on your projects.
1.- Create a new environment:
conda create --name the-name-of-environment
2.- To activate the environment:
conda activate the-name-of-environment
3.- To get a list of your environment:
conda env list
4.- In order to use our envelopes in Jupyter we must install ipykernel:
conda install -c anaconda ipykernel
5.- To use the-name-of-environment in a Jupyter notebook:
python -m ipykernel install --user --name=the-name-of-environment
6.- Now run a Jupyter notebook:
jupyter notebook
Now you can select the environment you have created with all the libraries installed and run your projects in Jupyter Notebook!
Branches in Git
The branches in Git are something magical, at first they can create confusion in your head, but once you get the hang of them, they’re a great tool.
I recently had an experience with having to restore a complete repository that I had on GitHub but not on my computer, and I had to do a lot of research and documentation to restore all the branches that I made at the time. I leave it to you as a gift in a SUPER CHEAT under these lines ;-)
List all local branches
git branch
List all remote branches
git branch -r
Create new branch and switch to this branch
git checkout -b <name-of-the-new-branch>
Delete a branch
git branch -d <name-of-the-new-branch>
SUPER CHEAT: Restore locally ALL remote branches!
I confess that the first time I had to do this was in the middle of my Data Analytics bootcamp in Ironhack, and I remember that it was exhausting because I was a little lost, I had accidentally removed a steering and I had to restore about 17 branches one by one, horrible..
With this bash code in your Terminal, you will get a copy in your local of ALL the branches you have in remote, and believe me this is wonderful.
#!/bin/bash
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
git branch --track "${branch##*/}" "$branch"
donegit fetch --all
git pull --all
These are some of the most valuable keys that will help you create virtual environments for your development projects and work with Git. I hope they serve you as much as they do me, and I’ll be able to update these contents very soon.
If you liked my article about “My Git & Conda cheat sheet 🚀” and you want to know more about my future articles, you can follow me in Medium @borjauria and in Twitter @borjauria.