Session 6: Integration with GitLab / GitHub

Track, organize and share your work: An introduction to Git for research

Course at Max Planck Institute for Human Development

Slides | Source

License: CC BY 4.0 DOI

14:00

1 Last session: Branches

Last session: Learning objectives

After the last session, you should now be able to answer the following questions / do the following:

đź’ˇ You understand the purpose and benefits of using branches in Git
đź’ˇ You can create and switch between branches
đź’ˇ You can merge branches and resolve merge conflicts
đź’ˇ You can name at least three best practices when working with branches

Last session: recipes project

At the end of this session, you should have accomplished the following:

  1. You created a new branch and merged changes to your main branch
  2. You created and resolved a merge conflict

Please keep the recipes folder! We will continue to use it in the following sessions.

2 This session: Integration with GitLab / GitHub

Integration with GitLab / GitHub

Image from Techdobz

Reading

https://lennartwittkuhn.com/version-control-book/chapters/remotes-intro.html

Learning objectives

đź’ˇ You can connect your local Git to a remote repository service.
đź’ˇ You can create a remote repository.
đź’ˇ You can pull and push changes to and from a remote repository.

Cheatsheet

Command Description
git remote Manages remote repositories
git clone Creates a local copy of a repository
git pull Fetches and merges the latest changes from a remote repository into the current branch
git fetch Updates remote tracking branches
git push Uploads local commits to a remote repository

Tasks

In this session, you will work on the following tasks:

  1. Reading: Read the chapter “Remotes - Introduction” in the Version Control Book.
  2. Implementation: Try out the commands in the chapter.
  3. Exercises: Work on the exercises for the recipes project.
  4. Quiz: Test your knowledge with the quiz.

As always:

  1. Try out the commands of this session and play around with them.
  2. Check whether you have achieved the learning objectives.
  3. Ask questions!
  4. Let’s git started!

recipes project

At the end of this session, you should have accomplished the following:

  1. You connected your GitHub account to your local Git.
  2. You created a new GitHub repository and uploaded (i.e., “pushed”) your recipes project.
  3. You collaborated on a shared project by adding and committing changes to a partner’s repository.
  4. You created and reviewed a pull request to integrate new content from a partner.

Optional:

  1. You cleaned up your project by deleting unnecessary files and branches.
  2. You created a short README.md file in your repository.

Please keep the recipes folder! We will continue to use it in the following sessions.

Exercises

1. Upload and manage your repository on MPIB GitLab or GitHub

Connect to MPIB GitLab or GitHub

  1. Generate a personal access token (PAT) on GitHub.
  2. Use the PAT for GitHub authentication.

“Push” your repository

  1. Create an empty internal repository on MPIB GitLab or private repository on GitHub.
  2. Set the remote URL for your local recipes Git repository.
  3. Push your main branch to MPIB GitLab or GitHub.

2. “Private” collaboration with pull requests (using “GitHub Flow”)

  1. Add your partner (desk neighbor) as a collaborator to your recipes repository.
  2. Clone your partner’s repository.
  3. Create a new branch in your partner’s repository.
  4. Add and commit a recipe to your partner’s recipes.txt file.
  5. Push the changes on the new branch to MPIB GitLab / GitHub.
  6. Create a Merge Request / Pull Request.
  7. Review and merge the PR your partner made in your repository.
  8. 🚀 Optional: Add additional changes on the branch pushed by your collaborator.

🚀 Optional: Create a README.md file

  1. Navigate to your repository on GitHub, click “Add file”, and select “Create new file”.
  2. Name the file README.md, add a brief description of your project, and provide a commit message. Play around with Markdown syntax!
  3. Click the green “Commit new file” button to save the README.md file to the repository.
  4. Pull the changes to your local repository.

🚀 Optional: Manage branches

  1. Push another branch (other than the default branch) with changes to MPIB GitLab or GitHub.
  2. Delete any unused or merged branches.

🚀 Optional: Clean up your repository on MPIB GitLab or GitHub

  1. Delete unnecessary files or add a new recipe directly on MPIB GitLab or GitHub.
  2. Commit changes on MPIB GitLab or GitHub with a message.
  3. Pull the changes to your local repository.

🚀 Optional: Clone and sync your repo

  1. Clone your repository from MPIB GitLab or GitHub to a different location on your computer.
  2. Stage, commit and push changes in the new location (consider using a new branch).
  3. Pull changes to the repository in the original location.
  4. Delete your newly cloned repository.

3 Appendix

Cloning

Cloning

  • Remember to clone a repo in a sensible location (not in your own repository)
  • To rename the cloned repo you can use: git clone <URL> new-folder-name