Instructor Notes

This is a placeholder file. Please add content here.

Introduction


Branches


Remote Repositories


Create and Modify Connections

The git remote command also lets you manage connections with other repositories. The following commands will modify the repo’s ./.git/config file. The result of the following commands can also be achieved by directly editing the ./.git/config file with a text editor.

Create a new connection to a remote repository. After adding a remote, you’ll be able to use <name> as a convenient shortcut for <url> in other Git commands.

BASH

git remote add <name> <url>

Remove the connection:

BASH

git remote rm <name>

Rename a connection:

BASH

git remote rename <old-name> <new-name>

To get high-level information about the remote <name>:

BASH

git show <name>

Exercise: Add a connection to your neighbour’s repository. Having this kind of access to individual developers’ repositories makes it possible to collaborate outside of the central repository. This can be very useful for small teams working on a large project.

BASH

git remote add john http://dev.example.com/john.git

Starting a branch from the main repository state:

Remember that when you create a new branch without specifying a starting point, then the starting point will be the current state and branch. In order to avoid confusion, ALWAYS branch from the stable version. Here is how you would branch from your own origin/main branch:

BASH

git fetch origin main
git checkout -b <branch> origin/main

You must fetch first so that you have the most recent state of the repository.

If there is another “true” version/state of the project, then this connection may be set as upstream (or something else). Upstream is a common name for the stable repository, then the sequence will be:

BASH

git fetch upstream main
git checkout -b <branch> upstream/main

Now we can set the MPIA version of our repository as the upstream for our local copy.

Challenge

Setting the upstream repository

Set the https://github.com/mpi-astronomy/advanced-git-training as the upstream locally.

Then, examine the state of your repository with git branch, git remote -v, git remote show upstream

BASH

git remote add upstream https://github.com/mpi-astronomy/advanced-git-training.git
git fetch upstream
git checkout -b develop upstream/develop




BASH

git remote add upstream https://github.com/mpi-astronomy/advanced-git-training.git
git fetch upstream
git checkout -b develop upstream/develop


Undoing Changes


Merging


Tags


Branching Models


Forking Workflow


Data Science Workflow


Large Files


Undo, Move, cherry-pickWhat is a cherry-pick?


Interactive Rebase and Squash


Hooks


Setting up the Command Prompt


Additional Resources