Skip to content

Latest commit

 

History

History
101 lines (75 loc) · 1.67 KB

git.md

File metadata and controls

101 lines (75 loc) · 1.67 KB

Git

Book

upcoming:

  • cherry-picking
  • force-with-lease
  • squash

Basics

initialize empty git repo git init <repo-name>

push repo to remote:

git remote add origin <repo-url>
git push origin master

clone repo locally
git clone <repo-url>

configuration

git config --global user.email "[email protected]"
git config --global user.name "user"

repository status
git status

specific filechanges
git diff <file-name>

get quick overview of last repo change
git log --oneline

undo changes
git revert <git-hash>

add file to staging area
git add <filename>

commit changes to repo
git commit -m '<commit-message>'

push changes to remote server
git push

get latest changes from remote
git pull

ignore files and dirs by adding their relative paths to the following file
.gitignore

Branching

create new branch
git checkout -B '<new-branch-name>'

delete branch
git branch -D '<branch-to-delete>'

upcoming: rebase

Inspect recent changes

e.g. for the src dir,
git whatchanged --since="last Sunday" -p -- src

Fixing detached HEAD, when on feature branch

git pull --rebase origin main
git log
git push --force

Remove all git history from repo

#!/usr/local/bin/bash

# prerequisites:
# all tags deleted
# main branch is the only branch that exists

: '
git checkout --orphan last
git add -A
git commit -am "feat: rewrite git history" --no-verify
git branch -D main
git branch -m main
git push -f origin main -v
cd .git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
# check size:
du -hs .
du -hs .git
'