miscellaneous_tips:20_software_development:git_notes:git_repositories

# 'git' Repositories

Change into the project's base directory and type:

git init .


A bare repository should be created using the parameter –bare. Conventionally, the name of a bare repository ends in .git, e.g. my_repo.git. If the bare repository is to be shared between several users then the –shared parameter should also be specified, otherwise other users may not have sufficient permissions to commit to this repo.

git init --bare --shared my_repo.git


Remote references a usually referred to by a short name assigned to a specific URL.

The commonly used default short name is origin. However, if you have several remote repositories, or you generally want to see where the remote repository is located, you can use more meaningful names like gitlab or github instead of simply origin.

You can specify the preferred name with the -o parameter when you clone a remote repo, or just use the preferred name when you add a remote repo to the local one.

Create the new remote repo first, then run these commands:

git remote add origin new-URL-for-origin
git push -u origin master


where

• origin is just the default name of the remote when the project is cloned. Any name can be used instead.
• master is the default name of the master branch. The name of any existing branch can be used instead.
• Current versions of git prefer to use the name main instead of master.

Thus, alternative commands might be:

git remote add gitlab new-URL-for-gitlab
git push -u gitlab main


If an existing remote repo has been moved to a different location then the remote URL in the local repo has to be updated:

git remote set-url origin new-URL-for-origin


where

• origin is just the default name of the remote, but can be any other name of an existing remote.

Thus, if the short name for the remote is gitlab, this command has to be used instead:

git remote set-url gitlab new-URL-for-gitlab


Martin Burnicki martin.burnicki@burnicki.net, last updated 2021-07-29

• miscellaneous_tips/20_software_development/git_notes/git_repositories.txt
• Zuletzt geändert: 2021-07-29 18:22
• von martin