In this post, I am going to show you best (and easy) practices for cloning a Github repo to your local macbook computer and create a virtual environment to contain your work. Cloning a Github repo means that we are create a copy of a Github repo in our local computer. All the files including test data, along with the actual code files will be downloaded.
Before starting, if you are going to keep any private data (webhook urls, private keys etc..) in the repository files, you may want to make a private clone of the public repository:
For this, create a new PRIVATE repository on Github.
Then, do a bare clone of the public repo:
#create a bare clone git clone --bare https://github.com/exampleuser/public-repo.git #go to the bare clone directory cd public-repo.git #push the bare clone to your private repo git push --mirror https://github.com/yourname/private-repo.git #go to the upper directory and delete the bare clone cd .. rm -rf public-repo.git
Now, we want to clone the private repo so you can work on it:
#Clone the private repo so you can work on it git clone https://github.com/yourname/private-repo.git cd private-repo make some changes git commit git push origin master
If you want to pull new updates from the public repo:
cd private-repo git remote add public https://github.com/exampleuser/public-repo.git git pull public master # Creates a merge commit git push origin master
Create a virtual environment for our local repository:
Now, we have created our local copy of Github repository, now it’a good idea to create a virtual environment. We will install all required libraries into the virtual environment and this will prevent library conflicts.
python3 -m venv your_environment_name
We can name our virtual environment anyway we wish, but it’s a good practice to name it as the Github folder. For this example, let’s call our virtual environment as linode_discord_venv:
python3 -m venv linode_discord_venv
In order to activate the virtual environment, we need to call it with source:
In order to deactivate it, just call the command:
You may want git to ignore your virtual environment:
In order to do that, add the name of the folder with a trailing slash to your .gitignore file.