Don't be overwhelmed. Everyone learns as they go along, but make sure you have a nice [setup](https://docs.gitlab.com/ee/tutorials/learn_git.html) and understand the [basics](https://docs.gitlab.com/ee/tutorials/learn_git.html).
## HowTo add a specific ssh-key for your git account
## HowTo add a specific ssh-key for your git account
Sometimes it might be useful to have different ssh-keys per project or have a special ssh-key just for github/gitlab.
Steps:
...
...
@@ -46,7 +51,86 @@ These urls should not show `https`, if there is a `https` then you will need to
Every git repository can be cloned using https, but for ssh-key access you need the `git@...` version (usually there are two options: `ssh`, and `https`).
## HowTo Sync a GitHub and a GitLab repository
## How To Setup an Access Token in Git?
In your [GitLab account](https://gitlab.phaidra.org/-/profile/preferences) you can define *Access Tokens*, which can be used to share git access to your projects with some API or Server. This is preferred to storing you GitLab credentials. The best option is of course to use ssh-keys with a passphrase (even a simple one).
Steps:
1. Account Settings
2. Access tokens
3. add new token
4. Specify *Token Name*
5. Specify *Expiration date*
6. Specify *scope*, which can be full access (**api**) or just read (**read_api**). There are multiple options. [docs](https://gitlab.phaidra.org/help/user/profile/personal_access_tokens.md#personal-access-token-scopes)
7. Create
8. Clone the repo with **HTTPS** url.
9. Store this token for easy access:
```sh
# Store or cache (in .git-credentials)
# or use an personal access token (can only be used for git operations)
It is easy to import a GitHub repo into GitLab and the otherway around. However, if you want to make sure you can have both repos at the same state, you need to syncronize them.
How to call: `./git-repos-sync [URL1] [URL2] [Branch]`
...
...
@@ -93,3 +177,15 @@ chmod +x git-repos-sync
# execute the script
./git-repos-sync [URL] [URL] [Branch]
```
## How To Sync Gitlab and GitHub Repositories?
You can set up some CI/CD yourself, but Gitlab will automatically do this for you:
1. Go to *"Settings > Repository > Mirroring repositories"*
2. Enter your Github repo with your username in front `https://<github username>@github.com/path/to/your/repo.git`
3. In the password field, enter your Github token
4. push is the only option for our GitLab
5. Press Mirror repository
Whenever you push something to GitLab it will automatically sync that with GitHub, if it can. If there are different commit on both repos, then it does not do it.