3. Remote git

Setting up a remote repository as a backup

Back up your work!

When doing research, or back in undergrad, we all heard the common refrain “back up your work!”

  • This sometimes involved floppy disks, usb sticks, external harddrives;
  • Also now likely to include cloud platforms and storage options (Dropbox, OneDrive, etc.)

Back up your work!

Laptop on fire!

secumem, CC BY-SA 3.0, via Wikimedia Commons

Back up your work!

Network of computers

We need a back-up!

The “backup” of our local git repository is called a remote repository.

Remote repository

The remote repository can be:

  • on a different computer
  • on an external harddrive
  • on a cloud service like GitHub

Remote repository

%%{
  init: {
    'theme': 'base',
    'themeVariables': {
      'primaryColor': '#9fe1ff',
      'primaryTextColor': '#470044',
      'primaryBorderColor': '#000000',
      'lineColor': '#9158A2',
      'secondaryColor': '#e79aff',
      'tertiaryColor': '#fffc58'
    }
  }
}%%

flowchart TD
    Untracked -->|**git add**| Staged
    Staged -->|**git commit**| Committed
    Committed -.->|*edit files*| Untracked

%%{
  init: {
    'theme': 'base',
    'themeVariables': {
      'primaryColor': '#9fe1ff',
      'primaryTextColor': '#470044',
      'primaryBorderColor': '#000000',
      'lineColor': '#9158A2',
      'secondaryColor': '#e79aff',
      'tertiaryColor': '#fffc58'
    }
  }
}%%

gitGraph
   commit id: "a1b2c3d"
   commit id: "4e5f678"
   commit id: "90abcde"
   commit id: "7835cd3"
   commit id: "34efc1a"
   commit id: "cb45ad1"
   commit id: "456abc1"
   commit id: "ad1cb45"
   commit id: "def134a"

%%{
  init: {
    'theme': 'base',
    'themeVariables': {
      'primaryColor': '#9fe1ff',
      'primaryTextColor': '#470044',
      'primaryBorderColor': '#000000',
      'lineColor': '#9158A2',
      'secondaryColor': '#e79aff',
      'tertiaryColor': '#fffc58'
    }
  }
}%%

flowchart TD
    Local -->|**git push**| Remote
    Remote -.->|**pull**| Local

  • You can push bundles of commits to your remote repository
  • You can also pull changes from the remote repository to your local…
    • You can have different “local” repositories on different machines…

Remote repository

%%{
  init: {
    'theme': 'base',
    'themeVariables': {
      'primaryColor': '#9fe1ff',
      'primaryTextColor': '#470044',
      'primaryBorderColor': '#000000',
      'lineColor': '#9158A2',
      'secondaryColor': '#e79aff',
      'tertiaryColor': '#fffc58'
    }
  }
}%%

flowchart TD
    Local-1 -->|**push**| Remote
    Remote -.->|**pull**| Local-1

Remote repository

%%{
  init: {
    'theme': 'base',
    'themeVariables': {
      'primaryColor': '#9fe1ff',
      'primaryTextColor': '#470044',
      'primaryBorderColor': '#000000',
      'lineColor': '#9158A2',
      'secondaryColor': '#e79aff',
      'tertiaryColor': '#fffc58'
    }
  }
}%%

flowchart TD
    Local-1 -->|**push**| Remote
    Remote -.->|**pull**| Local-1
    Remote -.->|**pull**| Local-2

Remote repository

%%{
  init: {
    'theme': 'base',
    'themeVariables': {
      'primaryColor': '#9fe1ff',
      'primaryTextColor': '#470044',
      'primaryBorderColor': '#000000',
      'lineColor': '#9158A2',
      'secondaryColor': '#e79aff',
      'tertiaryColor': '#fffc58'
    }
  }
}%%

flowchart TD
    Local-1 -->|**push**| Remote
    Remote -.->|**pull**| Local-1
    Remote -.->|**pull**| Local-2
    Local-2 -->|**push**| Remote

  • You can use a remote repository to sync repositories across different machines
  • For yourself, or for collaborators

Remote git

%%{
  init: {
    'theme': 'base',
    'themeVariables': {
      'primaryColor': '#9fe1ff',
      'primaryTextColor': '#470044',
      'primaryBorderColor': '#000000',
      'lineColor': '#9158A2',
      'secondaryColor': '#e79aff',
      'tertiaryColor': '#fffc58'
    },
    'gitGraph': {
      'showBranches': true,
      'showCommitLabel': false,
      'mainBranchName': 'main (remote)',
      'mainBranchOrder': 2}
  }
}%%

gitGraph
   commit
   commit
   branch 'mmq-patch-01' order: 1
   commit
   commit
   checkout 'main (remote)'
   merge 'mmq-patch-01'
   branch 'pt-patch-01' order:3
   checkout 'pt-patch-01'
   commit
   commit
   checkout 'pt-patch-01'
   checkout 'main (remote)'
   merge 'pt-patch-01'

This allows us to collaborate with others

GitHub

In the same way that we are focussing on Git, we are going to focus on GitHub for this course

  • There are lots of things we can get GitHub to do that are not “version control” specific; we will link to these in the “extended reading” section at the end of the course.
  • For now, lets think of it as a remote repository for git.

Sharing your git repo

Open access icon

Learn by doing

The best way to get used to using git is by actually using it, which brings us on to our next practical…

  • Edit files
  • git add <filename>
  • git commit -m "sensible git message"
  • New: git push origin main