Git
git init REPO
Latest updates on branch
git push -u
git fetch
git pull
git pull origin branch
git merge origin/colob-branch
git status
$ git commit -a -m "MESSAGE"
# or
# git add FILE
# git commit -m "MESSAGE"
$ git push origin master
$ git branch
$ git log
Clone a branch
git clone -b develop git@github.com:user/myproject.git
Contributing to a repo
Hit the fork button on GitHub
Clone the package from your account git clone https://github.com/USERNAME/PACKAGE.git
cd PACKAGE
conda create -n test_env python=3.7
conda activate test_env
pip install -e .
git remote add upstream https://github.com/HOST/PACKAGE.git
git checkout -b shiny-new-feature
git fetch upstream
git rebase upstream/master
Do cool stuff
git commit -a -m "message"
git push origin shiny-new-feature
conda deactivate
Test the update:
conda remove --name test_env2 --all
conda create -n test_env2 python=3.7
pip install git+https://github.com/USERNAME/PACKAGE.git@shiny-new-feature
OR
Checkout a branch
$ git checkout branchname
Checkout a branch from upstream/master
$ git checkout upstream/master
$ git checkout -b new-branch
See branches
$ git branch -a
Resolve conflicts
$ git merge main
Stash commits
Skip pre-commit
git commit --no-verify -m "Error"
See servers
$ git remote -v
See path
git rev-parse --show-toplevel
Revert to an old commit
$ git log
$ git checkout XXXXXX
$ git checkout -b branch
Remove a file (changes to a file) in a PR
git diff HEAD~N FILE > out.txt
git apply -R out.txt
Update credentials before commiting
git config user.name "USERNAME"
git config user.email "EMAIL@DOMAIN.com"
Update author in a commit
git commit --amend --author="USERNAME <EMAIL@DOMAIN.com>"
Exit git log
q
Git restore
$ git restore file
Delete a branch using GitHub
See git tags
git tag
git tag -l
git describe --long --always --first-parent
Create a tag
git tag -a 0.0.1 -m "version 0.0.1" && git push origin 0.0.1
Delete a tag
git tag --delete 0.0.1
git push origin --delete 0.0.1
See first commit
$ git rev-list --max-parents=0 HEAD
You can then copy this into GitHub to find the date of the commit.
Python
GitPython
from git import Repo
repo = Repo(".")
new_version = "2022.8.14"
repo.create_tag(new_version, message="Version release")
repo.remote().push(new_version)