Skip to content
Mael Rouxel-Labbé edited this page Mar 28, 2024 · 1 revision

Table of Contents

We collect here questions already raised on the cgal-dev mailing list or stated below.

Note that the Git project already has a huge FAQ: https://git.wiki.kernel.org/index.php/GitFaq

Which clients?

On Linux/macOS, Git comes as command line tool. Please refer to your package manager to install it. You can also install Git from sources (https://www.git-scm.com/downloads).

There are also many GUI available, for instance

  • Windows: TortoiseGit (which is similar to TortoiseSVN), SmartGit, GitEye
  • macOS: Sourcetree, Tower, SmartGit, GitEye

... and many others. Please explore the web (e.g. https://git-scm.com/downloads/guis) to find your preferred one.

How much space do I need on my disk?

With git clone <url>, you receive a full repository with all branches as existing on the server. In addition, the branch master will be checked out. A clone of cgal.git needs about 1 GB. A clone of cgal-web.git also needs about 1.6 GB.

How can I see which branch I am on?

The command

> git branch

displays all the local branches with a star, '*', in front of the current branch.

The first line of the 'status' command also displays the branch:

> git status

There is also a shell prompt, see https://nuclearsquid.com/writings/git-new-workdir/.

What if I want to work on multiple branches in parallel?

If you are working on several branches at a time and for several reasons you do not want to switch all the time, there are different possibilities to handle multiple working directories.

Duplicating directories

The command

> git clone cgal cgal-other

creates a copy of the repository (very quickly since it uses hardlinks), but the configuration files of Git are not duplicated (they are symlinked) and it extends the tree of Git repositories by one additional child.

Git-worktree

Added in Git 2.5, the command git-worktree allows to manage multiple working trees. Indeed,

> git-worktree add -b <new_branch> <path> <branch>

creates a folder path and creates a new branch new_branch starting at the branch branch into it. For example, suppose that your cgal clone is in /home/jenny/CGAL/Git/cgal, do:

> cd /home/jenny/CGAL/Git/cgal
> git-worktree add -b Convex_hull_3-make_it_faster-jenny ../new_folder cgal/master

See https://git-scm.com/docs/git-worktree for more information.

Recommendation: It is convenient to name the new working tree as the new branch, that is:

 > git-worktree add -b Convex_hull_3-make_it_faster-jenny Convex_hull_3-make_it_faster <branch>

Git-new-workdir

For older versions of Git, the script git-new-workdir can be used (see https://github.com/git/git/blob/master/contrib/workdir/git-new-workdir and https://nuclearsquid.com/writings/git-new-workdir/) as an alternative to git-worktree. It provides the command

> git new-workdir <repo> <dir>

A third parameter can be used to name the branch you want to checkout.

Note for Windows users: git-new-workdir needs symbolic links. Do not try to use it on Windows unless you only use git.exe from Cygwin. Git.exe from msysgit or Tortoise will not work with such a working directory.

We also discuss (for advanced users) how to combine several orthogonal features in one branch.

How to remove old branches that are already merged

The command git branch --merged cgal/master lists all local branches that are already merged into cgal/master. (Note that integration and master are usually seen as merged into master.) The following command remove all such branches, but integration and master:

> git branch --merged cgal/master | grep -vE 'master|integration' | xargs -n 1 git branch -d<br />

(adaptation from a StackOverflow answer)

How can I disable/change the pager used by some Git commands?

Git sends the output of some commands to a pager (like less or more). If you don't like that, e.g., because the used pager does not understand the escape sequences for colors, the pager can be disabled or changed with the command

> git config --global core.pager cat

cat effectively disables paging. A different pager can be set by supplying the command name there.

How can Git ignore files globally?

See this nice tutorial.

How to create aliases for Git commands?

See that page: https://git.wiki.kernel.org/index.php/Aliases.

How to search for the commits of a certain author?

 > git log -p --author="Jenny"

My branch is really old. I would like to update it to get latest update from master.

Assuming you are currently working on a branch called my-branch.

# Checkout to your branch if not already done
> git checkout my-branch

#fetch the cgal repository to get it up to date
> git fetch cgal

# Merge the cgal/master branch into your own. It will
# pull all new commits into your branch, and github
# will be able to make the difference between your commits
# and the ones from master.
> git merge cgal/master

# Then resolve conflicts, if there are any. You can also review the changes
# made by the merge with the following command:
> git diff --staged

# Once you resolved everything, you can commit that merge:
> git commit

# If your branch does not track any remote branch yet, you need to use the
# -u option when you push. If it is already done, you don't nee dit anymore.
> git push -u cgal-public-dev my-branch
# note -u is equivalent to --set-upstream

Other alternative if you have not shared your branch with others

If your branch hasn't been shared with others (e.g. you have not pushed it to a remote or you are absolutely sure that no one has done any work based on your branch), you can forget the above procedure and rebase your branch from an updated master. Rebasing is the process of replaying your commits on top of an updated upstream.

This should not be done if you simply intend to merge your branch to master because it hides the actual integration changes that would usually be represented by the differences of the merge commit.

# switch to your ancient feature
> git checkout my-ancient-feature
> git rebase cgal/master
# follow the instructions of the output of rebase, fix conflicts

Be warned that if you use git-rebase while other developers also work on the same branch, their next git-pull will show a lot of conflicts!

I want to rename a local branch, without renaming the upstream branch (in cgal-public-dev)

Just do:

> git branch -m <oldname> <newname>

I see remote branches in my repository that have been removed on the server. How do I update my local clone?

> git fetch -p

will do the job

If you have more than one remote, you can add the option --all to apply it to all of them.

> git fetch --all -p

SSH and Tortoise-Git on Windows

When installing git for Windows from github.io:

  • Tick OpenSSH library
  • Set GIT_SSH = TortoisePlink.exe
  • No need for alias for ssh or scp, instead with Cygwin setup install: ssh and ssh-pageant
  • No need for a directory .ssh as the keys are stored in pageant
Clone this wiki locally