Difference between revisions of "Git"
(→Steps described) |
|||
Line 1: | Line 1: | ||
− | |||
To use git for your own and team projects, DTU Compute is providing a GitLab instance with all the benefits it offers. Primarily a place for your repositories, other features are or will become available. | To use git for your own and team projects, DTU Compute is providing a GitLab instance with all the benefits it offers. Primarily a place for your repositories, other features are or will become available. | ||
Revision as of 13:53, 28 August 2019
To use git for your own and team projects, DTU Compute is providing a GitLab instance with all the benefits it offers. Primarily a place for your repositories, other features are or will become available.
Login with your DTU credentials here: https://lab.compute.dtu.dk
Contents
Add your public keys
To access your private repositories, add your public SSH-key to your GitLab account.
If you don't have a SSH-key, on Linux/MacOS you can use this command in your favourite shell:
ssh-keygen
Press Enter
3 times to create a password-less key pair, located in:
$HOME/.ssh/id_rsa $HOME/.ssh/id_rsa.pub
The file id_rsa.pub
is your public key which you can share with other systems, including DTU Compute's GitLab.
To add your public key in GitLab, follow these steps after login:
1) In the top-right corner click your user icon
2) Click Settings and on the left-hand panel click SSH Keys
3) Follow the instructions from here
Give access to other users
To share a repository with other users, the user you want to add has to login to GitLab first. Then you can find and add them as a member of your project.
1) Select your project you want to share
2) In the left-hand panel select Settings -> Members
3) Under Select members to invite search for the username
More to come
Migrating from Gitolite to GitLab
Our Gitolite server (git.compute.dtu.dk) is considered deprecated, and everyone with active repositories there are encouraged to migrate. This can be done from a local PC with a cloned repo.
Migrating a repo requires a bit of manual work, but not much. What it basically comes down to, is moving the origin from Gitolite to GitLab. Here are the steps described as simple as possible:
- Make sure your locally cloned repo - incl. all branches, tags, etc. - is up to date with origin
- Create a new repository on GitLab using the same name as the repo you want to move
- Add a new remote using the URL from GitLab, and push everything to this remote
- Remove all references to the old remote (Gitolite)
- Rename the new remote to origin
- In GitLab add the users you want to share the project with.
- Users may want to clone the repo anew rather than change origin manually.
Steps described
As is shown above, it is pretty straight forward to move a repository, but as always the details are important. Here the steps will be described a bit more together with the commands to use.
First make sure that your local repository clone is up to date with origin (the gitolite server), and make sure that you checkout all remote branches locally.
git fetch origin git branch -a git checkout -b feature1 origin/feature1
Create the new replacement repository at https://lab.compute.dtu.dk and copy the SSH clone URL - eg. git@lab.compute.dtu.dk:user/project2.git
- to add a new remote in your local repo, and push all branches to this new remote, here called "new-origin".
git remote add new-origin git@lab.compute.dtu.dk:user/project2.git git push --all new-origin git push --tags new-origin # if you use tags
Delete the reference to the old origin and make the new remote the origin.
git remote rm origin git remote rename new-origin origin
Your repository is now migrated to GitLab.