Nuxeo Core Developer Guide

Installing Git

Updated: December 16, 2024

Installation

Download available at https://git-scm.com/download.

Creation of a GitHub Account

To be able to clone and push on the GitHub repository in read write mode, you need a GitHub account with the write access to the Nuxeo repositories.

Create your own account with your email address and configure your git to use the same address, for instance:

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

This will be stored in your ~/.gitconfig file.

Contributors don't need a write access to Nuxeo repositories since they will push changes to their own forked repositories and send pull-requests to Nuxeo.

Configuration

SSH Key

At Nuxeo, we use SSH for data transfer with GitHub. Therefore, you need to configure your SSH key. On the GitHub site, click Account Settings > Click SSH Public Keys > Click Add another public key and add your public key there. It will be used for authentication against any Git URL of the form `[email protected]:nuxeo/...`.

If you meet any problem during the configuration, please see GitHub's official documentation Connecting to GitHub with SSH.

Global Configuration

Here is a global Git configuration which enforces Nuxeo Git usage recommendations

git config --global core.autocrlf input
git config --global core.safecrlf warn
git config --global core.ignorecase false
git config --global core.whitespace trailing-space,space-before-tab
git config --global apply.whitespace fix
git config --global push.default upstream
git config --global merge.renormalize true
git config --global remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pull/*"

You can give a look at https://gist.github.com/jcarsique/24f8dd46d176bb67253e

Aliases

Aliases can be added to your personal configuration by running:

git config --global alias.aliasname command

For instance to add the "st" alias for the "status" command:

git config --global alias.st status

These aliases are stored in the ~/.gitconfig file, you can also edit it manually.

Here are some aliases inspired from our Mercurial usage and from our current experience with Git:

# Before Git 1.8.3 (May 24, 2013), remove the occurrences of `%C(auto)` or replace them with fixed colors such as `%Cgreen`, `%C(bold blue)`...

# Simple shortcuts
ls = "ls-tree --name-only"
ll = "ls-tree -l"
st = status -sb
ci = commit
co = checkout
br = branch
branches = branch -a
di = diff
dic = diff --staged
id = show -s --pretty=format:'%C(auto)%h%d'
rollback = git reset --soft HEAD^
# Because "pull --rebase" and "rebase" are finally more used than "pull" and "merge"
pullr = "!git fetch \"$@\" && git rebase --autostash @{push}"
# Because we sometimes really want a merge
pullnor = pull --no-rebase

# Amend a changeset (less powerful but quicker and easier than the interactive rebase)
 fix = "!_() { c=$(git rev-parse $1) && git commit --fixup $c && git -c core.editor=cat rebase -i --autosquash --keep-empty --autostash $c~; }; _"

# Using ref to upstream branch available since Git 1.7 (@{upstream})
# Incoming changes
in = "!git remote update -p; git log ..@{u}"
# Outgoing changes
out = log @{u}..
# Outgoing changes on all remote-tracked branches
outall = log --branches --not --remotes=origin
# Branch fork point (aka oldest ancestor)
oldest-ancestor = !bash -c 'diff -u1 <(git rev-list --first-parent "${1:-master}") <(git rev-list --first-parent "${2:-HEAD}") | sed -ne \"s/^ //p\"' -

# Various log display
lg = log --graph --pretty=format:'%C(auto)%h -%d %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
glog = log --graph --abbrev-commit --date=relative
logone = log --pretty=format:'%C(auto)%m %h %Cgreen%ad %C(blue)%<(20)%aN %Creset%s %N %C(auto)%d' --left-right --cherry-pick --date=short
# Latests changes since last pull
lc = log --pretty=oneline --abbrev-commit --graph --decorate ORIG_HEAD.. --stat --no-merges
# Latest updated branches
latest = for-each-ref --count=10 --sort=-committerdate --format='%(committerdate:short) %(refname:short)'
# Latest updated local branches
latestl = for-each-ref --count=10 --sort=-committerdate refs/heads --format='%(committerdate:short) %(refname:short)'

# Commits per user
who = "shortlog -ne --format='%h %s'"
# LoC per user (BSD)
authorship = "!git ls-files -z|xargs -0 -n1 -E'\n' -J {} git blame --date short -wCMcp '{}'| perl -pe 's/^.*?\\((.*?) +\\d{4}-\\d{2}-\\d{2} +\\d+\\).*/\\1/'| sort | uniq -c | sort -rn"
# LoC per user (GNU)
authorship = "!git ls-files -z|xargs -0 -n1 -E'\n' | git blame --date short -wCMcp -- | perl -pe 's/^.*?\\((.*?) +\\d{4}-\\d{2}-\\d{2} +\\d+\\).*/\\1/'| sort | uniq -c | sort -rn"

rbranch-rename = "!_() { [ \"$#\" -lt 2 ] && echo 'Usage: rbranch-rename [remote] old_branch_name new_branch_name' && exit 1; \
                       if [ \"$#\" -gt 2 ]; then REMOTE=$1; shift; else REMOTE=origin; fi; git push $REMOTE $REMOTE/$1:refs/heads/$2 :$1; }; _"

# See https://gist.github.com/jcarsique/24f8dd46d176bb67253e for more aliases.

Integration

Bash Integration with Volnitsky Project

Far from perfect, its advantage is to also manage Mercurial and Subversion repositories.

See http://volnitsky.com/project/git-prompt/

Bash/Zsh Integration with Git Contribution

Clone https://github.com/git/git

Then add into your ~/.profile, ~/.bashrc or ~/.zshrc the following:

# Git prompt
source ~/path_to_git_clone/contrib/completion/git-prompt.sh
# Git completion; import the file corresponding to your Shell:
source ~/path_to_git_clone/contrib/completion/git-completion.bash
source ~/path_to_git_clone/contrib/completion/git-completion.zsh

# Additional custom changes
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWSTASHSTATE=1
GIT_PS1_SHOWUPSTREAM="auto verbose"
# Reduce PWD in prompt to last 30 chars of PWD
function truncate_pwd
{
  newPWD="${PWD/#$HOME/~/}"
  local pwdmaxlen=100
  if [ ${#newPWD} -gt $pwdmaxlen ]
  then
    newPWD="...${newPWD: -$pwdmaxlen}"
  fi
}
PROMPT_COMMAND=truncate_pwd
PS1='$? [\[\033[1;35m\]$newPWD$(__git_ps1 " \[\033[1;34m\](%s)")\[\033[0m\]]\$ '

Helpful Documentation

http://help.github.com/linux-set-up-git/