Codeberg/Community
54
325
Fork
You've already forked Community
12

Confused organizing git for Codeberg *and* Github #1931

Open
opened 2025年05月14日 17:36:24 +02:00 by Miq19 · 6 comments

Comment

I am still in transition from Github to Codeberg, so I got some repositories still residing on Github, while others are on Codeberg already.

Now I created a new local repository for a project, developed for a while and now wanted to push it to Codeberg to create a new repo there - and miserably am failing at it.

What I did so far:

  • did a git init
  • added all files belonging to the repo
  • made a git commit

But now when trying to push the project to Codeberg I am running into numerous issues.

git config --list gives me

credential.provider=generic
credential.helper=cache
credential.https://github.com.helper=!/usr/bin/gh auth git-credential
user.email=_my_mail_address_
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=main
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://Miq19@codeberg.org/Miq19/Bridge
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

When I will do a git push -u origin master (was master by default, sorry) the system will hang forever until I Ctrl-C it.

I suppose the culprit is the credential.helper or credential.https, but what will I have to set to be able to sync to both Github and Codeberg?

Oh, by the way: I am using 2FA with an authenticator app to authenticate on Codeberg and Github.

### Comment I am still in transition from Github to Codeberg, so I got some repositories still residing on Github, while others are on Codeberg already. Now I created a new local repository for a project, developed for a while and now wanted to push it to Codeberg to create a new repo there - and miserably am failing at it. What I did so far: - did a ``git init`` - added all files belonging to the repo - made a ``git commit`` But now when trying to push the project to Codeberg I am running into numerous issues. ``git config --list`` gives me ``` credential.provider=generic credential.helper=cache credential.https://github.com.helper=!/usr/bin/gh auth git-credential user.email=_my_mail_address_ credential.https://dev.azure.com.usehttppath=true init.defaultbranch=main core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true remote.origin.url=https://Miq19@codeberg.org/Miq19/Bridge remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* ``` When I will do a ``git push -u origin master`` (was ``master`` by default, sorry) the system will hang forever until I ``Ctrl-C`` it. I suppose the culprit is the ``credential.helper`` or ``credential.https``, but what will I have to set to be able to sync to both Github and Codeberg? Oh, by the way: I am using 2FA with an authenticator app to authenticate on Codeberg and Github.
Author
Copy link

Solved it for now and for Codeberg only:

  • created a personal access token
  • created an empty repository with the matching name on the web interface
  • git push -u origin master
  • enter user name and access token in the pop-up dialog

I still would like to know how to use different, but global authentication for Github and Codeberg.

Solved it for now and for Codeberg only: - created a personal access token - created an empty repository with the matching name on the web interface - ``git push -u origin master`` - enter user name and access token in the pop-up dialog I still would like to know how to use different, but global authentication for Github and Codeberg.

Create two remotes:

git remote add codeberg https://Miq19@codeberg.org/Miq19/Bridge
git remote add github https://Miq19@github.com/Miq19/Bridge

and then

git push codeberg master
git push github master
Create two remotes: ``` git remote add codeberg https://Miq19@codeberg.org/Miq19/Bridge git remote add github https://Miq19@github.com/Miq19/Bridge ``` and then ``` git push codeberg master git push github master ```
Author
Copy link

That would solve another issue - assessing the very same repository on Github and Codeberg.

My question was meant opposite:

  • having a number of repositories on Github and another set on Codeberg
  • all cloned locally into their own folders
  • How is it possible to set the credentials globally for Github and Codeberg (2 sets) to not have to re-enter these again and again whenever pushing one of those repositories

Something like "If the local repository has a remote on Github, apply the Github credentials, if it resides on Codeberg, use the Codeberg ones".

Could I make myself better understandable now?

That would solve another issue - assessing the very same repository on Github and Codeberg. My question was meant opposite: - having a number of repositories on Github and another set on Codeberg - all cloned locally into their own folders - How is it possible to set the credentials *globally* for Github and Codeberg (2 sets) to not have to re-enter these again and again whenever pushing one of those repositories Something like "If the local repository has a remote on Github, apply the Github credentials, if it resides on Codeberg, use the Codeberg ones". Could I make myself better understandable now?

Basically there are two different protocols you can use for pulling and pushing your repositories (https and ssh). You are using https protocol but for scenario you described it seems ssh is more suitable.

I am not sure whether you are Linux, MacOS or Windows user.
If you are using linux or macos just open command line prompt. If you have Windows open gitbash.

Generate your private and public key pair (if you dont have it already)

ssh-keygen

Accept default location and you can provide short passphrase to protect your private key.
When your key pair is generated, open public key (file with *.pub extension) in any text editor and copy its content into clipboard.
Go to your Github/Codeberg settings into ssh / gpg keys menu and add new ssh key and copy content from your clipboard there.

Now you will use the same key for both Github and Codeberg.
If you have provided non-empty passphrase during key creation you will be allways prompted for it.

You can run this command to avoid prompting all the time

eval $(ssh-agent)
ssh-add

In case of ssh protocol you will need to use little bit different url format:

git remote add codeberg ssh://git@codeberg.org/Miq19/Bridge.git 
git remote add github ssh://git@github.com/Miq19/Bridge.git 
Basically there are two different protocols you can use for pulling and pushing your repositories (https and ssh). You are using `https` protocol but for scenario you described it seems `ssh` is more suitable. I am not sure whether you are Linux, MacOS or Windows user. If you are using linux or macos just open command line prompt. If you have Windows open gitbash. Generate your private and public key pair (if you dont have it already) ``` ssh-keygen ``` Accept default location and you can provide short passphrase to protect your private key. When your key pair is generated, open public key (file with *.pub extension) in any text editor and copy its content into clipboard. Go to your Github/Codeberg settings into `ssh / gpg keys` menu and add new ssh key and copy content from your clipboard there. Now you will use the same key for both Github and Codeberg. If you have provided non-empty passphrase during key creation you will be allways prompted for it. You can run this command to avoid prompting all the time ``` eval $(ssh-agent) ssh-add ``` In case of ssh protocol you will need to use little bit different url format: ``` git remote add codeberg ssh://git@codeberg.org/Miq19/Bridge.git git remote add github ssh://git@github.com/Miq19/Bridge.git ```
Author
Copy link

@berk76 Thanks, that sounds like a slick solution.

I tried it and installed the ssh keys, but when trying to sync a repository on Codeberg (first I tried) I got

> git pull --tags origin main
fatal: couldn't find remote ref main

The main branch is named main.

[Edit] Found it, accidentially. Instead of git remote add codeberg ssh://... I need to name it git remote add origin ssh://...

@berk76 Thanks, that sounds like a slick solution. I tried it and installed the ssh keys, but when trying to sync a repository on Codeberg (first I tried) I got ``` > git pull --tags origin main fatal: couldn't find remote ref main ``` The main branch *is* named ``main``. [Edit] Found it, accidentially. Instead of ``git remote add codeberg ssh://... `` I need to name it ``git remote add origin ssh://...``

Bascally, you can have one or more remotes. Convention is that default one is named origin but it is not mandatory - you can name them as you want.

Bascally, you can have one or more remotes. Convention is that default one is named `origin` but it is not mandatory - you can name them as you want.
Sign in to join this conversation.
No Branch/Tag specified
main
No results found.
Labels
Clear labels
accessibility

Reduces accessibility and is thus a "bug" for certain user groups on Codeberg.
bug

Something is not working the way it should. Does not concern outages.
bug
infrastructure

Errors evidently caused by infrastructure malfunctions or outages
Codeberg

This issue involves Codeberg's downstream modifications and settings and/or Codeberg's structures.
contributions welcome

Please join the discussion and consider contributing a PR!
docs

No bug, but an improvement to the docs or UI description will help
duplicate

This issue or pull request already exists
enhancement

New feature
infrastructure

Involves changes to the server setups, use `bug/infrastructure` for infrastructure-related user errors.
legal

An issue directly involving legal compliance
licence / ToS

involving questions about the ToS, especially licencing compliance
please chill
we are volunteers

Please consider editing your posts and remember that there is a human on the other side. We get that you are frustrated, but it's harder for us to help you this way.
public relations

Things related to Codeberg's external communication
question

More information is needed
question
user support

This issue contains a clearly stated problem. However, it is not clear whether we have to fix anything on Codeberg's end, but we're helping them fix it and/or find the cause.
s/Forgejo

Related to Forgejo. Please also check Forgejo's issue tracker.
s/Forgejo/migration

Migration related issues in Forgejo
s/Pages

Issues related to the Codeberg Pages feature
s/Weblate

Issue is related to the Weblate instance at https://translate.codeberg.org
s/Woodpecker

Woodpecker CI related issue
security

involves improvements to the sites security
service

Add a new service to the Codeberg ecosystem (instead of implementing into Gitea)
upstream

An open issue or pull request to an upstream repository to fix this issue (partially or completely) exists (i.e. Gitea, Forgejo, etc.)
wontfix

Codeberg's current set of contributors are not planning to spend time on delegating this issue.
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Codeberg/Community#1931
Reference in a new issue
Codeberg/Community
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?