Notes

Here are some notes I took and I like to refer to.


Git

Last update: March 5th, 2020

Push local changes to GitHub

The GitHub repo has already been initialized and the local and remote branches are in sync.

  1. git add .
  2. git status
  3. git commit -m "Commit comment"
  4. git push origin master

Start a new Git repository

  1. Initialize local directory: git init
  2. Add local repository: git add <option>
    • <.> everything in the current directory, same as --all or -A
    • <file> all changes in file.
    • <directory> all changes in the target directory.
    • <-p> interactive staging, let you choose files one by one.
  3. Commit repository: git commit -m "First commit message"
  4. Add remote repo URL (like GitHub): git remote add origin https://.../your-repo.git
  5. Push local repo to GitHub: git push -u origin master
    • <-u> will remember your preferences for remote and branch and you can simply use the command git push next time.

Configure username & email

  1. git config --global user.name "FIRST_NAME LAST_NAME"
  2. git config --global user.email "MY_NAME@example.com"
    • Use <--global> if it’s for every repo, dont use it if it’s for a specific repo.

Display configuration file: *cat .git/config

Show & change remote URL

  1. Run git remote -v to list the existing remotes and see their names and URLs
    • The output will look something like this:
      origin https://github.com/user/repo_name.git (fetch)
      origin https://github.com/user/repo_name.git (push)
  2. Run git remote set-url followed by the remote name and URL:
    • Example: git remote set-url origin git@gitserver.com:user/repo_name.git
    • The command updates the repository .git/config file with a new URL to the remote repository.
    • You can edit the file directly but should use the git command.
    • The remote’s URL can start with HTTPS or SSH (defaults to SSH if not specified).
    • The URL can be found on the repository page of your Git hosting service.
  3. Verify that the remote’s URL was successfully changed by listing it again with git remote -v

Update local branch with remote master

If your local branch is behind the remote master:

  • git checkout [master/main]
  • git pull
  • git checkout [my-branch-which-is-behind]
  • git merge master

Git will ask for a commit message.

Top


Python

Last update: May 27th, 2020

Virtual environment (venv)

Official documentation.

  1. Create new virtual environment: python3 -m venv /path/.../venv
  2. Activate the new environment: source ./venv/bin/activate
  3. Deactivate environment: deactivate
  4. Check what packages are in the environment: pip3 freeze
  5. Install packages with pip: pip install <package name>

Top