Week 4 Discussion - Git and Github & Nephology#

What are Git and GitHub?#

Exercise 105

  1. What does tracking changes in context of Git mean?

  2. Why is it important?

Exercise 106

  1. What is the difference between Git and Github?

  2. Do you know other sites similar to Github?

Exercise 107

What does the following quote mean in the context of git?

Your closest collaborator is you six months ago, but you don’t reply to emails.

Solution to

Git is typically used to collaborate with others, but git can also assist you even you are working alone in a project.

Imagine you begin a project but after a while you need to get other priorities done. After six months you want to continue your former project but cannot remember your last state. In this moment you would wish that you could speak with yourself six months ago, but you cannot send to your former self an email.

You can use git also as a project diary which may assist you in a long-lasting project.

For the source of this quote look at this post

Setting Up Git and GitHub#

Exercise 108

How did you install Git?

A. Was already installed. A. Using apt A. Using homebrew A. Using a graphical installer A. Other

Exercise 109

Before we can create a change using Git (called commit) we have to provide a name and email. What could be the reason?

Getting Started with Git#

Exercise 110

You are working in a directory.

  1. How can you start tracking these files in Git?

  2. How can you see if a directory is tracked by Git?

Exercise 111

After some time you want to continue with your personal project that you track using Git.

  1. Which command would be helpful to see the current status of tracking?

  2. The status indicates that you have a change to be committed. Which language does Git use to describe this?

Exercise 112

Imagine that you have a repository with a text file and a directory, which contains many photos.

# Create an example repository
mkdir my-diary; cd my-diary
git init
echo My dairy > diary.txt
mkdir img
curl https://picsum.photos/200 -sLo img/IMG_9217.jpg
curl https://picsum.photos/200 -sLo img/IMG_9218.jpg
git add .
git commit -m Initial
  1. What do the following commands do?

    1cd my-diary
    2sed -i 's/dairy/diary/g' diary.txt
    3git commit diary.txt -m 'fixed typos'
    4git mv img/{IMG,2020-12-04}_9217.jpg
    5git mv img/{IMG,2021-11-xx}_9218.jpg
    6git commit -m 'annotated image dates'
    
  2. What do a commit and to commit mean?

  3. What would happen if we would run the third line without the argument diary.txt?

  4. How can we alternatively commit the changes in diary.txt?

  5. Why could have the user used two different commits instead of a single one?

Exercise 113

You committed your changes but forgot to add an additional file to your commit. How can you amend your changes?

Important Git Features#

Getting Help, Logs, and Diffs#

Exercise 114

You are working on a Python project and use Git to track your changes. Before calling it a day you want to commit your changes. You see that you modified many files but forgot what. Which command is useful to see your changes to create appropriate commits?

Exercise 115

You forgot what the -A option in git add -A does. How can you look that up?

Ignoring Files#

Exercise 116

You are working on a Git repo. Your text editor has a backup feature, which saves the files that you are working with using the name FILENAME.EXTENSION.bak. These files clearly should not be committed. How can you solve this problem?

Branching#

Exercise 117

You are participating in a software project in your company and your team uses Git. You and your partner propose a major change to your team which introduces several modifications in the graphical user interface (GUI) of the software. You do not want to break the software while working on the new features.

  1. How can you leverage branches for this purpose?

  2. You tested your shiny GUI, demonstrated it with pride to your team and your team welcomed that. Which commands would you use to integrate the new features to the software?

Github#

Exercise 118

When you are creating a new repository on Github, you have the following options:

Public

Anyone on the internet can see this repository. You choose who can commit.

Private

You choose who can see and commit to this repository.

  1. When would you choose which option? Give an example.

  2. What are the pros and cons of settings your repo public/private?

Exercise 119

When you are creating a new repository on Github, you have the following options for initializing your project:

  1. Add a README file

  2. Add .gitignore

  3. Choose a license

What are the advantages of adding these files to your project?

Exercise 120

  1. What is the difference between a local and remote repository?

  2. When would you use a remote repository?

Markdown#

Exercise 121

  1. What is Markdown?

  2. What is its advantage?

Exercise 122

Mark up the following text in Markdown. Use Markdown’s markup features wherever you can.

You can directly work on an interactive editor like Markdown Editor

2021-11-12

Morning

Woke up very early at 4 with heavy eyes. Probably I am stressed. It could be related to:

deadlines at work
my stressful phone call with my mother

I listened to the podcast Short Stuff: Your Dirty Bed to fall into sleep again

https://www.iheart.com/podcast/105-stuff-you-should-know-26940277/episode/short-stuff-your-dirty-bed-89082486/

Afternoon

The following Bash code creates random files with random content, lovely!

for i in {1..10}
do
    echo $RANDOM > $(mktemp XXX.txt); echo $i
done

The command mktemp generates random files, and $RANDOM expands to a random integer.

Evening

Now I know how T-Shirts are designed 😀:

https://img-9gag-fun.9cache.com/photo/4077402_700bwp_v1.webp

vocabulary: to bring so. up to speed means to make sure that someone has all the latest info about something.

Pull requests#

Exercise 123

What is the difference between a pull request and git merge?

Exercise 124

Imagine you have accepted a pull request on GitHub and merged the changes into your main branch. Then you continue to work on your local repository on the main branch, but you cannot see the merged changes. What could be the problem?

Pages#

Exercise 125

When you are creating GitHub pages for your repository you have the option to select a theme. How it is possible that the same Markdown code looks differently for different themes?

Exercise 126

Look at GitHub Pages. What is the advantage of creating a repository called USERNAME.github.io over activating GitHub Pages for a repo?

Forking#

Exercise 127

GitLab is an alternative to the Git management software GitHub. GitLab calls pull requests merge requests.

Create a merge request for the following repo, which uses GitLab:

https://mygit.th-deg.de/lsi/the-unix-workbench-notes

Your merge request could contain for instance:

  • an improvement of a solution

  • fix for a typo

  • an additional line on the guest book

Summary and reflection#

Did you reach the following learning objectives for this week? Discuss with your partner.

  • Use Git to track versions of code

  • Use GitHub to create a remote Git repository

  • Create Git branches

  • Fork GitHub repositories and open a pull requests