Efficient Python Tricks and Tools for
Data Scientists - By Khuyen Tran
Git and GitHub
GitHub View on GitHub Book View Book
This section shows some tricks and tools to work with Git and
GitHub.
GitHub CLI: Brings GitHub to Your
Terminal
If you create a local folder before creating a GitHub repository for
it, you might need to go to the GitHub website then create a new
repository, then add a remote to your current folder. Is there any
way that all of these steps could be done in the terminal in 1 line of
code?
That is when GitHub CLI comes in handy. The code snippet below
shows how to create a new Github repository in your local folder.
$ cd your_local_folder
# Create an empty local git repo
$ git init
# Create a new GitHub repo
$ gh repo create
With GitHub CLI, you can also manage your pull requests, issues,
repositories, gists, and so much more! Check out GitHub CLI here.
Pull One File from Another Branch Using
Git
Pull the files from another branch into your branch can be messy.
What if you just want to pull one file from another branch? You can
easily to like that with the code snippet below:
# downloads contents from remote repository
$ git fetch
# navigate to another branch
$ git checkout
# adds a change in the working directory to
the staging area
$ git add
# captures the state of a project at that
point in time
$ git commit
Now you just update one file in your branch without messing with
the rest!
Download a File on GitHub Using wget
If you want to download a file on GitHub such as a csv file, instead
of cloning the repo, simply use the code snippet above. For
example, if the website the file you want to extract is https://github.
com/khuyentran1401/Data-science/blob/master/visualization/dropd
own/population.csv, type:
$ wget
https://raw.githubusercontent.com/khuyentran14
01/Data-
science/master/visualization/dropdown/populati
on.csv
Now the data is in your directory!
github1s: Read GitHub Code with VS
Code on your Browser in One Second
Syntax highlighting in VS Code makes it easy for you to
understand the source code. Is there a way that you can read
GitHub code with VS Code in 1 second?
Yes, there is. Simply replace ...
github.com/yourname/repository with
github1s.com/yourname/repository
... to view Github with VS Code. It should show up like below.
Here is an example.
Astral: Organize Your GitHub Stars with
Ease
I have been sharing many tools and you might not be able to keep
up with them. To save and organize the tools you discovered on
GitHub, you can use Astral.
With Astral, you can organize my starred GitHub repositories like
below.
I have been using this for months, and it is super quick when I want
to find the right tool for my project.
Link to Astral.
pip install -e: Install Forked GitHub
Repository Using Pip
Sometimes, you might fork and make some changes to the original
GitHub repository. If you want others to install your forked repo,
use
pip install -e
git+https://github.com/username/package.git#egg=pa
ckage.
The code below shows how to install the forked repo of NumPy.
$ pip install -e
git+https://github.com/khuyentran1401/numpy.gi
t#egg=numpy