How to git

How to git

The sheet for git / remote / local

Create git repo

git init

# Clone local
git clone $PATH_LOCAL $PATH_DEST

# Clone remote
git clone $URL_REMOTE $PATH_DEST

# SSH Clone remote
git clone user@server:/home/user/repo.git

Remote Repos

# Add remote repo with name and url
git remote add name <URL>

# Show all repos
git remote

# Set with token since 2021
# Settings → Developer settings → Personal access tokens → Generate_new

git remote set-url origin https://<token>@github.com/<username>/<repo
git push

Changes

# 1. Changes to stage
git add $FILE_NAME

git add * # All files

# 2. Commit from stage files
git commit -m "$MSG"

# One liner commit
git commit -a -m "$MSG"

# 3. Push to remote branch
git push remote branch # (git push origin master)

Branches

# List all braches
git branch / git branch -a

# Create and change to branch "feature"
git checkout -b feature

# Delete branch "feature"
git branch -d feature

# Change to Branch XY
git checkout $XY

# Merge from OTHER_BRANCH to actually
git merge OTHER_BRANCH

# Pull from remote repo
git pull OTHER_BRANCH_REMOTE

# Push branch feature to Remote (origin)
git push origin feature

Get latest changes and merge with local

# Get changes
git fetch origin

# Merge with repo origin branch master
git merge origin/master

# Or with this one-liner
git pull origin master

##
## Merge feature with actually branch
git merge feature

# Fetch branch from remote and update to local 
git fetch origin <remote-branch>:<local-branch>

Branch Rebasing / Cherrypicking

#Rebasing for (git log cleaning)
git rebase <workbranch> <branch>

#Cherrypicking <sha-commit>
git cherry-pick eeed5e79911f26d0d8e768a2ec387e7882f122de

Others

# User config
git config --global user.name "Suuhmer"
git config --global user.email suuhmer@coldwareveryday.com

# Get all
git config --global --list


# Before add / commit revert
git checkout -- $FILENAME

# Revert all files local with remote
git fetch origin
git reset --hard origin/master

# Get status
git status
# List view
git status -s

# Get L0g
git log --oneline --decorate
# --grep --help for more stuff 

# GTK 
gitk

Merging Lokal branch with Remote specific branch

git clone <URL> -b nightly xyz && cd xyz-git
git status
git branch -a
git remote add suuhmer2 https://github.com/suuhm/plugin.video.xstream-1
git branch -a
git fetch suuhmer2 --tags
git merge --allow-unrelated-histories suuhmer2/nightly