Create a New Repository#

This section provides a step-by-step introduction to get started with a new git repository.

Create a Local Repository#

As a first step we are navigating to our project folder, initializing the repository, staging all files and doing our first commit. A nice quick overview about those steps can be found here: https://githowto.com/.

cd path/to/my/local/repository
git init

Push the Local Repository to Remote#

In order to access your repository from different machines, you may want to synchronize your local git repository with a remote repository. While multiple companies offer free storage space overseas, we encourage you to use the infrastructure provided by the TU Braunschweig.

  1. Open https://git.rz.tu-bs.de in a browser and login with your SSO credentials

  2. Create a new project by clicking New project in the upper right croner

    • Select Create blank project

    • Choose a project name and a visibility (e.g. public) (can be changed later)

    • uncheck the option Initialize repository with a README

  3. In order to communicate from your local repository with gitlab it is necessary to create a secure connection, e.g., via an access token:

    • In the top-right corner, select your avatar.

    • Select Edit profile.

    • On the left sidebar, select Access Tokens.

    • Enter a name and optional expiry date for the token.

    • Select the desired scopes.

      • read_repository

      • write_repository

    • Select Create personal access token.

      Save the personal access token somewhere safe. After you leave the page, you no longer have access to the token.

    Note

    Alternatively, you can establish the connection by using a ssh key (https://docs.gitlab.com/ee/user/ssh.html). This option only works from within the TU network (from home, via a VPN connection). If ssh keys are new for your we encourage you to use an access token.

  4. Connect the local repository by going back to your project in the terminal:

    git remote add origin https://<token name>:<access token>@git.rz.tu-bs.de/<namespace>/<project name>
    

    Exchange the <placeholder> with the corresponding entries. Hint: Edit the above command in a text editor and copy-paste the correct expression into your terminal.

  5. Commit your changes

    git add .
    git commit -m "Initial commit"
    

    If it is the first time that you are committing from a computer, git may prompt you to configure your mail and email address. You need to follow these instructions in the terminal before you continue.

  6. Push your changes to the remote repository:

    git push --set-upstream origin main
    

    whereby origin is a shortcut for the address of your remote repository, and main is the name of the branch you are pushing to (for branching, see the section on advanced git topics.) After a new branch is pushed, further changes can be pushed by only typing:

    git push
    

If everything is working correctly, your files should now be visible in the gitlab web interface after refreshing your browser.

Standard Workflow#

Once everything is set up you can start working with git. A standard workflow looks like this:

  • Do some changes in your files.

  • Stage your changes and create a commit

    git add .
    git commit -m "I did this and that change"
    
  • Push the commits to the remote instance

    git push