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

Test the update:

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

https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-and-deleting-branches-within-your-repository#deleting-a-branch

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)