How to set up or join a git repository

The guide “ version control with git ” can be found here. Please read it before you continue.

Step-by-step guide

In order to set up or join a git repository, you have two options. Both will be presented in the following.

Choose option a if you want to join an existing remote repository .
Choose option b if you prefer to create a local repository . You can still add a remote repository later.

Option a may be less error-prone and easier to conduct.

Prerequisites

You need git installed and preferalby a SSH key set up. Please refer to our guide.

Option a: Clone a remote, existing repository

  1. Create a/Find the repository on your GitLab instance, e.g. git.rwth-aachen.de.

  2. Copy its address from Clone (you can find that online in your GitLab GUI), go to the directory where you want your repository to be contained within. Git will create a folder for the repository at that place. Clone the remote repository:

    # this might look somewhat like this
    cd /home/<user>/<projects>		# absolute linux path, adapt to your needs
    # or
    cd C:\Users\<user>\<projects>	# absolute windows path, adapt to your needs
    # or
    cd <projects>						# relative path, starting at <user>
    
    # replace the address with the one you copied
    git clone <remote_address>
    # e.g.
    git clone git@git.rwth-aachen.de:nfdi4ing/knowledge-base.git #note: requires SSH-keys to be set up
    # or
    git clone https://git.rwth-aachen.de/nfdi4ing/knowledge-base.git
    
    # move into your project(-folder)
    cd <repo_name>
    # e.g.
    cd knowledge-base
    

Congratulations, you have joined a remote repository!

Option b: Create a local repository and upload it

  1. Open the terminal and navigate to the directory, where you want your repository:

    # this might look somewhat like this
    cd /home/<user>/<projects>		# absolute linux path, adapt to your needs
    # or
    cd C:\Users\<user>\<projects>	# absolute windows path, adapt to your needs
    # or
    cd <projects>			# relative path, starting at <user>
    
    # create a folder for your repository and move into it
    mkdir <new_project>
    cd <new_project>
    # e.g.
    mkdir knowledge-base
    cd knowledge-base
    
  2. Initialize a repository:

    git init
    

    Now you have a local repository, and you can start with version control on your local computer.

    If you see a folder called .git, you have an option enabled to see hidden folders. This folder is important for the functionality of git and you should not modify it!

Upload your repository

For collaboration with others you now want to add a remote repository.

  1. Create a blank project (even without Readme.md, because we do not want any other branch existing) on your GitLab instance.

  2. Add the remote repository as such:

    git remote add <remote_name> <remote_address>
    
    # e.g.
    git remote add origin git@git.rwth-aachen.de:nfdi4ing/knowledge-base.git
    

    You can add multiple remote repositories. Therefore choose reasonable names for them. origin is the default name, if you clone a repository.

    The remote address is the one you copied from the button Clone in Option a, Step 2.

  3. Upload (push) your content online:

    git push --set-upstream <remote_name> <branch_name>
    
    # which at this stage should be
    git push --set-upstream origin master
    

See also