Arvutiteaduse instituut
  1. Kursused
  2. 2019/20 kevad
  3. Koostöövahendid tarkvaraarenduses (LTAT.05.009)
EN
Logi sisse

Koostöövahendid tarkvaraarenduses 2019/20 kevad

  • Main
  • Lessons
  • Resources

Practice 2: Git configuration, moving data on the repository

By the end of this practice, you will have:

  1. Configured your Git installation
  2. Created Git aliases
  3. Learned to create and clone repositories
  4. Learned to stage, reset, commit, remove files

Reminder: UNIX command line

In these practical sessions, you are encouraged to use Git Bash to run Git commands. Git Bash opens a command line window that allows you to interact with your Windows file system with UNIX commands. Here is a reminder on some of the commands that you might need in this course. If you can find your way around the file system of a computer using the UNIX command line already, feel free to skip this section.

PWD

PWD ("print working directory") shows you the path of the directory you are currently located in.

LS

LS ("list") shows the contents of the directory you are in, like dir in Windows command line.

To get more information, like last modified date and permissions for each file and directory, use the argument "l".

By default, hidden files and directories (with names starting with a period) are hidden. To show them, use the "a" argument.

Arguments are entered after the command, prefixed with a dash ("-"). So in order to show the full information about all the files, you can use:

$ ls -la

CD

CD ("change directory") moves you to another directory ("folder"). Use cd .. to go to the parent directory of the directory that you are in.

$ cd path/to/new/directory

MV

MV ("move") is used to move or rename a file. It takes the form:

$ mv oldname newname

As the result, the file "oldname" is moved to the location "newname".

CP

CP ("copy") copies a file to another location.

$ cp file newfile

RM

RM ("remove") is used to delete files. Note: it cannot delete directories, for this purpose use rmdir.

$ rm file

Configuring your Git

User credentials

In the last session, you already did some configuration - you added your name and e-mail address to the globa configuration file.

$ git config --global user.name "User Name"

Use the git config command to check that the global configuration still contains your name and e-mail address.

Editor

Another very important thing to configure in every Git installation is the default editor. Git will use this application to edit commit messages, hunks, and more.

The default editor is configured by the core.editor variable. Modify your global (user-specific) configuration file either with a code editor or the git configure command to point to the executable of your editor of choice. For example, if you're using Microsoft Visual Studio Code, use code, the command-line tool that opens the editor. If you're using Atom, use the atom command in your core.editor. If you don't want to use an IDE/code editor, you can just use notepad to open the Windows Notepad.

For other code editing software, first try googling if it is being installed with a command line tool, e.g. "launch *editor* from windows command line". If not, find the main exe file of the application and use it's path in configuration.

Aliases

As demonstrated in lecture, aliases are very useful for people who use Git regularly. Find some useful aliases and add them to your global configuration file. Take inspiration from the examples shown on the lecture slides or search online. Make sure that you understand what commands the aliases are for and what they're used for.

Repository creation

In today's session, we will create a repository from the command line.

  1. Create a new directory (hint: mkdir directory-name) and create a new BARE Git repository in it. Note the path of the repository (hint: pwd)
  2. Clone that repository somewhere else on your computer. When cloning local repositories, you don't have to specify a domain name or IP address of the machine, just the path is enough.
  • What remotes does the new repository have?
  1. Save the contents of your global configuration file in a file called config.txt, stage and commit the file to the repository and push it to the remote.
  2. We want to be able to back up the repository elsewhere. Log into your GitHub account and create a new repository. Do not add README or .gitignore files when creating the repository.
  3. Add the address of the repository as a new remote to your repository (hint: git remote add remote_name remote_address). Name the new remote "github".
  • What remotes does the repository have now?
  1. Push the contents of the repository to the "github" remote.
  2. Github has an extensive collection of .gitignore files for different languages and development environments: https://github.com/github/gitignore . Pick one for a language that you are familiar with and add and commit it to your repository. Look inside it - try to understand why some patterns of files are being ignored
  3. Edit config.txt - delete your name and add a short explanation about one of the files in your .gitignore to the end of the file (e.g. "__pycache__/ contains the bytecode of the compiled python program")
  4. Now assume we have two tasks - "remove name" and "explain file". Make a separate commit for each one. Use git add -p to stage only the hunk that you need, make a commit and then repeat the process for the next task. You may need to split or edit hunks.
  5. Push the changes to the GitHub repository.
  6. Use the git rm command to remove config.txt, commit the changes and push them to GitHub

When everything is done, send a link to the Github page of your repository to the instructor in Slack.

Don't forget to fill the Quiz!

  • Arvutiteaduse instituut
  • Loodus- ja täppisteaduste valdkond
  • Tartu Ülikool
Tehniliste probleemide või küsimuste korral kirjuta:

Kursuse sisu ja korralduslike küsimustega pöörduge kursuse korraldajate poole.
Õppematerjalide varalised autoriõigused kuuluvad Tartu Ülikoolile. Õppematerjalide kasutamine on lubatud autoriõiguse seaduses ettenähtud teose vaba kasutamise eesmärkidel ja tingimustel. Õppematerjalide kasutamisel on kasutaja kohustatud viitama õppematerjalide autorile.
Õppematerjalide kasutamine muudel eesmärkidel on lubatud ainult Tartu Ülikooli eelneval kirjalikul nõusolekul.
Courses’i keskkonna kasutustingimused