Skip to content
Márton Elekes edited this page Apr 27, 2023 · 60 revisions

Hosting

Tutorials

Interactive

Non-interactive

Branching models

Best practices

Cheat sheets

Visual summaries

Git CLI clients

  • Git (the Windows edition includes a Bash emulator)

Git GUI clients

Git in Eclipse

Crash course for SVN users

Videos

Tips

  • Resolving a merge conflict
    • Edit it (optionally using EGit's Merge Tool)
    • Mark as merged by adding it to the index
  • Set the execute permissions on the updated files
    • git update-index --chmod=+x <file>

Troubleshooting

  • SmartGit requires a 32-bit JDK or JRE to work. Possible error messages include:
    • "The JAVA_HOEME environment variable does not point to a working 32-bit JDK or JRE"

    • The SMARTGIT_JAVA_HOME variable is not set properly.

      The solution is to simply install a 32-bit JDK and set the SMARTGIT_JAVA_HOME environment variable accordingly (e.g. SMARTGIT_JAVA_HOME to c:\Program Files (x86)\Java\jdk1.8.0_111.

Trigger commit

git commit --allow-empty -m "Trigger build"

Search in all commits

git grep <regexp> $(git rev-list --all)

(source)

Search in all commits changing a certain file

git grep <regexp> $(git log --pretty=format:"%H" README.md) -- README.md

(alternative)

Check out all revisions of file

FILE_BASE=README ; FILE_EXT=.md ; FILE="$FILE_BASE$FILE_EXT" ; i=0 ; for HASH in $(git log --oneline "$FILE" | awk '{print $1}') ; do git show $HASH:"$FILE" > "$FILE_BASE-$i-$HASH$FILE_EXT" ; ((++i)) ; done

(untested alternative)

Find a certain file (e.g. README.md) at all remote branches

git branch -a | grep -oP "remotes/\K\S*" | xargs -n1 -I{} bash -c "git show {}:README.md 2>/dev/null | wc -l"

The file must contain LF for a non-zero result.

Find tracked files that were force-added otherwise they would be ignored

git ls-files -i --exclude-standard -c

(source)

Beep upon failed push

The git push command often fails if the remote contains changes which have not yet been applied to the local branch. To get a timely notification, add the following command to your ~/.bashrc file (play is provided by SoX in the sox package on Fedora):

git() {
    if [ ${#} -gt 1 ] && [ ${1} = "push" ]; then
      /usr/bin/git ${@} || play -q -n synth 0.05 sin 480
    else
      /usr/bin/git "${@}"
    fi
}

Or, in zsh (needs SoX – brew install sox):

function git {
    if [ ${#} -gt 1 ] && [ ${1} = "push" ]; then
      /usr/bin/git ${@} || play -q -n synth 0.05 sin 480
    else
      /usr/bin/git "${@}"
    fi
}

This example uses the play binary but other commands capable of producing a "beep" sound can also work.

Diff: differentiate between moved and changed code

git diff --color-moved

Sources: 1, 2.

Diffing Word documents

To create meaningful diffs between the binary .doc files, perform the following steps:

  1. Install the antiword package with apt/dnf.

  2. Add the following section to your ~/.gitconfig file:

[diff "word"]
  textconv = antiword
  1. In the cloned repository, create the file .git/info/attributes and add the following:
*.doc diff=word
  1. Git diffs (git show, git diff, git diff --staged, etc.) should now show meaningful diffs for .doc files.

Fetching branches from GitHub PRs

For PR 57, do:

git fetch origin pull/57/head:pull-57
git checkout pull-57

Starring repositories on GitHub

Some assume starring repositories on GitHub is just a like. It also seems to serve another purpose: it allows keeping the contributions of the repositories you contributed to.

We recommend starring any repositories you contribute to. That way, your commits to those repositories will remain in your contributions graph even if you leave the organization that owns the repository or delete your fork of the repository.

(source)

Clone this wiki locally