====== 'git' Repositories ====== \\ ===== Create a Local 'git' Repositiory in an Existing Project ===== Change into the project's base directory and type: git init . \\ ==== Create a Bare, Shared Remote Repository ==== 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 ~~codedoc:clean:--~~bare ~~codedoc:clean:--~~shared ~~codedoc:my_repo.git~~ \\ ===== References to Remote Repositories ===== 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. \\ ==== Add a New Remote Repo to an Existing Local Repo ==== [[#Create A Bare, Shared Remote Repository|Create the new remote repo]] first, then run these commands: git remote add ~~codedoc:origin~~ ~~codedoc:new-URL-for-origin~~ git push -u ~~codedoc:origin~~ ~~codedoc: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 ~~codedoc:gitlab~~ ~~codedoc:new-URL-for-gitlab~~ git push -u ~~codedoc:gitlab~~ ~~codedoc:main~~ \\ ==== Change URL Of an Existing Remote ==== 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 ~~codedoc:origin~~ ~~codedoc: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 ~~codedoc:gitlab~~ ~~codedoc:new-URL-for-gitlab~~ ---- --- //Martin Burnicki [[martin.burnicki@burnicki.net]], last updated 2021-07-29//