Setting up & Operating GIT repositories

Client Setup

identify yourself

git config user.name $USER@$HOSTNAME
git config user.email $USER@$HOSTNAME

git config --global user.name $USER@$HOSTNAME
git config --global user.email $USER@$HOSTNAME

otherwise

git config --edit
git config --global --edit

and check

git config user.name
git config user.email

git config --global user.name
git config --global user.email

define some better defaults — FF + REBASE MANUALLY

#git config pull.rebase false       # merge (the default strategy)
#git config pull.rebase true        # rebase
git config pull.ff only         # fast-forward only

#git config --global pull.rebase false  # merge (the default strategy)
#git config --global pull.rebase true   # rebase
git config --global pull.ff only    # fast-forward only

moar options

#git config --global push.default simple
#git config --global core.editor elvis

Basic usage

see the last commit diff

git log --patch -1

see past commit changes and diff

git log
git show COMMIT --stat
git diff PREVIOUS-COMMIT COMMIT

see what’s been staged for commit already

git diff --cached --stat
git diff --cached
git status -v

Dirty speed-up tweaks

for text or html files, eventually avoid comments

git config --global alias.nc 'commit -a --allow-empty-message -m ""'
git config --global alias.ci 'commit --allow-empty-message -m ""'
git config --get-regexp alias

–or– directly use the shell aliases for that matter

alias push='git commit -a --allow-empty-message -m "" && git push'
alias commit='git commit --allow-empty-message -m ""'
alias stat='git diff --stat --cached origin/master'

Fetching a repository

Github

git clone git@github.com:ACCOUNT/REPO.git
#git clone https://github.com/pbraun9/slackbuilds.git

Gitlab on-premises

git clone ssh://git@gitsrv/home/git/project.git
#git clone http://git@gitsrv/home/git/project.git
#git clone https://git@gitsrv/home/git/project.git

GIT in production

update the list of branches and switch to the new revision

    git fetch -a
    git checkout release-1.1.0
    git pull

and restart the application

Troubleshooting

you’ve commited while loosing sync, and when trying to pull, you get

    fatal: Not possible to fast-forward, aborting.

==>

    git pull --rebase

another similar use-case

    "hint: Updates were rejected because the remote contains work that you do"

==> either the former or

    git merge

and eventually compare git log output, identify the additional commits there are and show diffs against those

    git diff-tree -p COMMIT

ca

don’t forget to define your trust store, you need to do that manually on NetBSD

git config --global http.sslVerify true

raw control chars

when doing git diff

ESC[32m+ESC[mESC[32m#

==> either find out where on earth the default behavior for less got changed (some old slackware release doing -M?… –or– enable “raw” control characters in your PAGER

git config --global core.pager "less -r"

share a repo across the file-system

If you need to share a repo with another user, using group permissions as such

#homedir does not need to be writable, but executable
chmod 750 /home/gollum/
cd /home/gollum/

#now making the repo writable for the group
chown -R gollum:gollum pub.git/
find pub.git/ -type d -exec chmod 770 {} \;
find pub.git/ -type f -exec chmod 660 {} \;
find pub.git/ ! -type d ! -type f

you need to fsck/prune/repack/fsck after changing perms. The link (see below) even says you need to do it on both sides, local and remote.

git fsck
git prune
git repack
git fsck

Resources

How to show what a commit did? https://stackoverflow.com/questions/1157818/how-to-show-what-a-commit-did

8.1 Customizing Git - Git Configuration https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#Basic-Client-Configuration

Show File Diffs When Viewing Git Log https://til.hashrocket.com/posts/8ii3emcrda-show-file-diffs-when-viewing-git-log

The Git Hater’s Guide http://www.evan.org/Fun/Git/index.htm

10 things I hate about Git https://stevebennett.me/2012/02/24/10-things-i-hate-about-git/

List Git aliases https://stackoverflow.com/questions/7066325/list-git-aliases

How to see the changes in a Git commit? https://stackoverflow.com/questions/17563726/how-to-see-the-changes-in-a-git-commit

git: can’t push (unpacker error) related to permission issues https://stackoverflow.com/questions/4025708/git-cant-push-unpacker-error-related-to-permission-issues

settings

Why use –ff-only over –rebase https://blog.sffc.xyz/post/185195398930/why-you-should-use-git-pull-ff-only-git-is-a

usage

https://stackoverflow.com/questions/13787109/how-to-see-changes-to-a-file-before-commit/13787903

https://linuxize.com/post/change-git-commit-message/

fetch in git doesn’t get all branches https://stackoverflow.com/questions/11623862/fetch-in-git-doesnt-get-all-branches


How do I show the changes which have been staged? https://stackoverflow.com/questions/1587846/how-do-i-show-the-changes-which-have-been-staged

git-diff - Show changes between commits, commit and working tree, etc https://git-scm.com/docs/git-diff

Git - deleted some files locally, how do I get them from a remote repository https://stackoverflow.com/questions/4235431/git-deleted-some-files-locally-how-do-i-get-them-from-a-remote-repository


Exploring History https://swcarpentry.github.io/git-novice/05-history/

2.3 Git Basics - Viewing the Commit History https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History

How To Switch Branch on Git https://devconnected.com/how-to-switch-branch-on-git/


https://stackoverflow.com/questions/2452226/master-branch-and-origin-master-have-diverged-how-to-undiverge-branches

https://akhromieiev.com/master-branch-and-origin-master-have-diverged/


https://stackoverflow.com/questions/13106179/fatal-not-possible-to-fast-forward-aborting

https://stackoverflow.com/questions/13846300/how-to-make-git-pull-use-rebase-by-default-for-all-my-repositories

https://spin.atomicobject.com/2020/05/05/git-configurations-default/


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5
Copyright © 2022 Pierre-Philipp Braun