Initializing a Git repository
Open git bash in the folder you would like to create a remote repo
Type: git init -b main
If you existing files in your local repo, type: git add . This should be followed by: git commit -m "First commit"
Create a new repository on GitHub.com. To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub. I always keep the name of my local folder the same as my GitHub repo. Not sure what happens if the name of the two folders are different.
At the top of your repository on GitHub.com's Quick Setup page, copy the remote repository URL
In your git bash type: git remote add origin <REMOTE_URL>
Verify using: git remote -v
If you committed any changes earlier, push them to main (GitHub): git push origin main
Update your remote GitHub repo to you local working directory by repeating the steps: add, commit, pull, push
To create a gitignore file, eg. to ignore IPython notebook checkpoints, use https://www.toptal.com/developers/gitignore
There are open source softwares available to generate Readme.md files for your repo based on your code. I haven't used them yet, so I will update when I am more familiar with the process.
Virtual environment setup
To create a virtual environment for a new project:
create a new project folder
go into that folder, open cmd in that folder
type python -m venv projectvenvname
To activate the virtual environment go to ./projectvenvname/scripts and then type activate.
For mac users, type source ./projectvenvname/bin/activate
At this point, you may be required to update your pip and install the latest Jupyter notebook. Type in the following command:
python -m pip install --upgrade pip
python -m pip install notebook
To add that virtual environment to Jupyter notebook:
python -m ipykernel install --user --name=projectvenvname
You can list all the virtual enviroments added to jupyter using the command (may be required to activate virtual env)
jupyter kernelspec list
To remove a virtual env from jupyter type:
jupyter kernelspec uninstall projectvenvname
References:
1) https://janakiev.com/blog/jupyter-virtual-envs/
3) https://realpython.com/python-virtual-environments-a-primer/
How to git clone someone else's repo
We will refer to someone else's repository as the other repository.
Create a new repository at github.com. (This is your repository). Give it the same name as the other repository. Don't initialize it with a README, .gitignore, or license.
Clone the other repository to your local machine. (if you haven't done so already). git clone https://github.com/other-account/other-repository.git
Rename the local repository's current 'origin' to 'upstream'. git remote rename origin upstream
Give the local repository an 'origin' that points to your repository. git remote add origin https://github.com/your-account/your-repository.git
Push the local repository to your repository on GitHub. git push origin main. Now 'origin' points to your repository & 'upstream' points to the other repository.
Create a new branch for your changes with git checkout -b my-feature-branch.
You can git commit as usual to your repository.
Use git pull upstream main to pull changes from the other repository to your main branch.
Visual Code Shortcuts
Auto-format you code using: Shift+Alt+F
Setting up git on macOS
Install homebrew
run: brew update
run: brew install git
if git is installed before, which you can check using git --version, run brew upgrade git
Follow the instructions for Initializing a git repo