Skip to content
Peter Kietzmann edited this page Apr 10, 2015 · 8 revisions

Git cheatsheet

How to checkout the (read-only) git repository

git clone git://github.com/RIOT-OS/RIOT.git

If you require write access, please contact the RIOT-team via email.

You may additionally want to checkout the platform configuration and initialization code from

git clone git://github.com/RIOT-OS/boards.git

or

git clone git://github.com/RIOT-OS/thirdparty_boards.git

Exemplary projects can be found in the projects repository:

git clone git://github.com/RIOT-OS/projects.git

Switch from read-only to read-writable repository

Edit the file @.git/config@ within your local repository and replace

    url = git://github.com/RIOT-OS/RIOT.git

by

   url = git@github.com:RIOT-OS/RIOT.git

How to track a branch

Example for the stable branch:

git branch --track stable origin/stable

How to create a release

  • (Examples are for release 0.01a)

Tag it using git tag:

  git tag -s 0.01a

Export the tag:

  git archive --format=tar --prefix=riot-0.01a/ 0.01a | gzip > riot-0.01a.tar.gz

colored diff

To have a colored output for all git projects execute:

git config --global color.ui auto

If you only want a colored output for your current git project, then omit the --global attribute.

This also shows whitespace errors in red.

How to rebase your master on a current RIOT master

To rebase your master, local and remote, on the current RIOT master:

  • switch to your master branch, i.e. git checkout master
  • apply git pull --rebase https://github.com/RIOT-OS/RIOT.git, to receive all changes from the RIOT master
  • and finally push your local rebased master to your repository, i.e. just git push

How to rebase a branch on the current RIOT master

To rebase your specific branch, local and remote:

  • rebase your master, as described above
  • switch to the branch you want to perform a rebase, e.g. git checkout my_cool_branch
  • apply git rebase master
    • solve appearing conflicts if happen
  • and if everything is done apply git push -f to update your repository with the rebased branch
    note: if not using the -f (force) option, git will complain your local branch diverges with your remote branch, and suggests you to first pull the changes (which usually would be not what you want)

How to squash commits

Squashing multiple commits to one is similar to the previous chapter How to rebase your master on a current RIOT master. When you are at that point to rebase the branch you are working in to the master branch, you use git rebase -i master. The -i option makes a list of all the commits in your branch that have to be rebased. You'll see something similar to this:

pick e71b606 This is commit message 1
pick b8edd56 This is commit message 2
pick 4030f5e This is commit message 3

# Rebase 7e60b65..4030f5e onto 7e60b65
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.

To squash commits, you need to write an s (instead of pick) before the respective commit. There are also other commands you can apply (as described in that file). Then you need to save (Ctrl + o and enter) and finish the rebase (Ctrl + x). After that you need to go on with solving possibly introduced conflicts and pushing to your remote repository, as described in the previous chapter.

Clone this wiki locally