GIT notes by Simon PJ

Configuration

Push only the current branch

When you say git push (with no arguments), push only only patches on
the current branch. If you have un-pushed commits on other branches, leave them be.

git config --global remote.origin.push HEAD

Creating tracking branches

Suppose you create a new branch on your local machine. Now you want to push
it up to the global repo. You almost certainly want your local branch to become
a tracking option of the remote one, so that git pull will merge changes to
the remote copy into your local copy.

git config --global branch.autosetupmerge true

Looking at the current state of affairs

Show one-line-per-file diff summary

Show a one-line-per-file summary of diffs between working files and the local repo:

git diff --stat

Show delta between branch and trunk

Show the commits that are on branch my-test but not on the main trunk:

git log `git merge-base master my-test`..my-test

The git merge-base b1 b2 thing returns the name of the commit that is the common ancestor of branches b1 and b2.

Working with branches

Create a branch after doing some edits

You are sitting on a branch (say master), and do some edits. Now you decide it wasn't as simple as you thought so you want to create a branch to keep your edits safe while you do something else.

git checkout -b <new-branch-name>

This creates the new branch and switches to it, but does not change your working files. Now you can safely commit on the branch ​Stackoverflow link. Then to push to the master repo:

git push origin <new-branch-name>

That will create <new-branch-name> in the master repo if it does not already exist.

Work on a branch gotten from the main repo

You have done a git fetch to get the upstream repo, which has a branch origin/experiment. You want a local experiment branch which tracks origin/experiment:

git checkout --track origin/experiment

This

creates a local branch experiment,

sets it up to track origin/experiment, and

checks it out

It will fail if local branch experiment already exists -- in that case you may want to do the --set-upstream thing (see next item).

Connect up a local branch with its remote counterpart

You are on local branch experiment and do git pull to pull down changes from origin/experiment, but you get this:

You asked me to pull without telling me which branch you
want to merge with, and 'branch.experiment.merge' in
your configuration file does not tell me, either. Please

Somehow you in a state where experiment isn't tracking origin/experiment. To make it tracking, use --set-upstream:

git branch --set-upstream experiment origin/experiment

git gui on Windows

I’ve been using git gui (on Windows at least) as a way to examine and stage changes. But I suddenly found that it wasn’t displaying the diff in the main pane.