Git

From My Mnemonic Rhyme
Revision as of 10:36, 25 March 2023 by Weiss (talk | contribs)
Jump to navigation Jump to search

Cheatsheet

Git Submodule

git submodule add git@github.com:tobiasweede/TobisUtils ./Assets/Scripts/TobisUtils

Git - Repo auf Webserver verfügbar machen

Mit einem normalen clone treten probleme aus, da der master branch als bearbeitet angesehen wird.

$ mkdir /var/www/www.example.org
$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f
$ chmod +x hooks/post-receive

Clone repository

git clone ssh://homaar@tobias-weiss.org:/home/homaar/java.git java

Create git repo

http://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server#_git_on_the_server

git init --bare --shared

On the Client:

git clone ssh://tobias-weiss.org/~/xyz.git
cd xyz
touch init
git add -A
git commit -m "init"
git push origin master

Reset to master

Maybe branch the work before resetting in order to preserve it:

git commit -a -m "Saving my work, just in case"
git branch my-saved-work

If all changes shall be resetet:

git fetch origin
git reset --hard origin/master

When only one single file shall be resetet:

git reset HEAD -- myFile # everything after -- is treated as filename

Git - Repo cleanen

git clean -n # show what will be deleted
git clean -xdf # rubber mallet method

Git - Lokale Files stashen

git stash
git stash show -p
git stash apply
git stash drop

view changed files

git whatchanged
# or
git diff

how to delete all commit history

git checkout --orphan newBranch
git add -A  # Add all files and commit them
git commit
git branch -D master  # Deletes the master branch
git branch -m master  # Rename the current branch to master
git push -f origin master  # Force push master branch to github
git gc --aggressive --prune=all     # remove the old files

rename branch

git branch -m new_name old_name

delete branch

#locally
git branch -d branch_name
#remote
git push <remote_name> --delete <branch_name>

push branch on remote server

git push -u origin branch_name

stash changes

git stash
git stash pop
git stash apply # keeps changes stashed
git stash drop
git stash clear # clear all stashed changes

push repo to new remote

https://stackoverflow.com/questions/20359936/import-an-existing-git-project-into-gitlab

cd existing_repo
git remote rename origin previous-hosts
git remote add gitlab git@git.hutber.com:hutber/kindred.com.git
git push -u gitlab --all
git push -u gitlab --tags

limit ram

git config --global pack.windowMemory "800m"
git config --global pack.packSizeLimit "100m"
git config --global pack.threads "1"