[← ppnm]

Exercise "Git/Mercurial"

Tasks

  1. Get yourself an account at one of the Distributed Version Control servers. Github, Gitlab, Bitbucket (which run Git only) are popular choices with free plans. Sourceforge (which runs both Git and Mercurial) is also popular. There is also a server at AU [gitlab.au.dk] but you will probably not be able to access it after graduation. Alternatively, any POSIX box with a static IP address running Apache and Git (like sdfeu.org) would do.

    Nowadays the code repositories use comparatively complicated authentication methods. Here is how you can do it in Github:

    1. You can use "access tokens". Here is the guide: [Github access with tokens].
    2. You can use SSH keys. Here is the guide: [Github access with SSH]. In short:
      1. Generate your own RSA keys at your box (if you haven't got them already):
        ssh-keygen -t rsa -N MyPassPhrase -f ~/.ssh/id_rsa
        
        where "MyPassPhrase" should be your own personal passphrase that you can remember. This creates a pair of keys: a public key ("~/.ssh/id_rsa.pub"), and a private key ("~/.ssh/id_rsa"). The passphrase is encoded in the keys. There is no way do decode it, so if you forget your passphrase you will need to generate new keys.
      2. In your Github settings go to "SSH and GPG keys" and click on "New SSH key". This will open a text area for the new key.
      3. Copy/paste the content of your public key file, "~/.ssh/id_rsa.pub", into this text area.
      Now you should have ssh access to your github from any account that has a copy of your private key ("~/.ssh/id_rsa") in the "~/.ssh" directory. Github will probably ask you for the passphrase of the key. You need to remember it.
  2. Read about Git at Bitbucket[] (or any other place) and/or about Mercurial at mercurial-scm.org.

  3. Install Git or Mercurial at your box,

    sudo apt install git
    
    or
    sudo apt install mercurial
    
  4. If you choose to use the ssh access to your server (which many servers support, I believe), generate a pair of RSA keys at your box,

    ssh-keygen -t rsa -N MyPassPhrase -f ~/.ssh/id_rsa
    
    and provide your server (must be somewhere in your settings) with a copy of your public key "~/.ssh/id_rsa.pub".

    If you choose some other authentication method, read the corresponding manual at your server.

  5. At your server: create a new project with an indicative name like "PPNM" :). You might need to read your server's documentation about how you do this.

  6. At your box:

    1. Make a directory for your repositories,
      mkdir ~/repos
      
    2. Go to your directory,
      cd ~/repos
      
    3. Clone your repository from the server to this directory,
      git clone address-of-your-repository
      
      or, if you use mercurial
      hg clone address-of-your-repository
      
    4. Do your exercises in (subdirectories of) this directory, add new files, commit changes, and push the commit to the server,
      git add --all
      git commit --all --message 'did this and that blah blah...'
      git push
      
      or, if you use mercurial,
      hg add
      hg commit --message 'an indicative message describing commit'
      hg push
      
      The long options can be abbreviated as -a and -m.