gretl git basics


Finding the repository on sourceforge
Getting a copy
Your personal git info
Updating your copy
Committing a change
Reverting local changes
Looking at diffs
Using git on MS Windows

Finding the repository on sourceforge

Go to the gretl project page at and select the Code item on the taskbar.

Getting a copy

Following on from the above: if you are not logged in you will see an instruction by means of which you can grab a read-only copy of the gretl-git sources, namely

  git clone git:// gretl-git

If you are logged in under your sourceforge USERNAME, and you have write privileges with git, you should see an instruction for getting a read-write copy, on the pattern

  git clone ssh:// gretl-git

These are shell commands. Obviously, if you need access to update translations you must use the second command.

Your personal git info

Before doing anything substantive with git you should ensure that your basic personal information (name and email address) is known to the program. This can be done via two shell commands on the pattern:

  git config --global "Your Name"
  git config --global "yourname@yourserver.ext"

As you might guess, the above commands will set username and email for any and all git repositories on your local machine, If you wish to set specific data for gretl commits, then change directory to your copy of the gretl-git repository and issue commands on the pattern above but omitting the --global option.

Updating your copy

The git command to update your copy of the source is

  git pull

So, very straightforward.

Committing a change

Having made a change that you wish to commit, you can do

  git commit <filenames>

to register changes to a specific file or files, or

  git commit -a

to commit any and all changes you have made. However, please note that in git the “commit” action does not upload your changes to the remote server (sourceforge). To do that you need add a “push”:

  git push

Reverting local changes

This information is relevant only for gretl developers, who are in the business of making changes in the gretl code-base. It may happen from time to time (I speak from experience!) that you make some changes in your local copy of the gretl git sources and then decide (before committing) that some of these changes are ill advised, and you want to roll them back.

In the old days of CVS you could simply delete a local file, then do a cvs update to restore the previous version from the repository. But -- watch out! -- git assumes that if you delete a file locally you mean to delete it from version control altogether. So you DO NOT want to do that. The (not very intuitive) git equivalent is

  git checkout .

This will revert changes to files that are already tracked by git (known to be part of the code base) but not already staged (set up for a push via the git commit command).

To revert local changes that you have already committed/staged but not yet pushed, there are two variants:

git reset --soft HEAD~
git reset --hard HEAD~

The first of these just uncommits the change, but does not revert the state of your local files to HEAD. The second both uncommits the changes and reverts your local files (or in other words, nukes your changes altogether).

For a lot more on reverting changes, see this GitHub blog entry.

Looking at diffs

To see any updates in your working copy relative to the sourceforge repository, it's simple:

git diff

To inspect differences for a specific file, append the name of the file to this command.

To see any updates made in the sourceforge repository relative to your working copy:

git fetch origin
git diff HEAD origin/master

Note that unlike pull, a fetch doesn't actually modify the files in your working copy, it just grabs information about what has changed in the repo.

Now suppose you've done a commit in your working copy but haven't yet (maybe inadvertently) done a push: how can you tell how your working copy differs from what's at sourceforge? Plain git diff won't do the job, but it's not so difficult:

git diff origin/master


To create a new branch, and then switch onto it:

git branch newbranch
git checkout newbranch

or use a shortcut: git checkout -b newbranch.

To switch back to master:

git checkout master

To merge newbranch into master:

git checkout master
git merge newbranch

To delete newbranch:

git branch -d newbranch

Using git on MS Windows

The following from beanstalk looks like a good guide: Working with Git on Windows.


John Anderson's 13 Git tips for Git's 13th birthday (April 2018): some nice refinements here!

Allin Cottrell, last revised 2018-05-04