Start Completely Fresh (Recommended for new platform)
# Remove the current git history
rm -rf .git
# Reinitialize git
git init
# Add your files
git add .
# Make initial commit
git commit -m "Initial commit"
# Add Codeberg remote
git remote add origin https://codeberg.org/your-username/your-repo.git
# Push fresh
git push -u origin main
This will push as a fresh project without any history. But if we want to keep the history, then there are two ways to do that.
1. We can just add a secondary repository to our project.
2. We can remove the previous repository and add the new one.
Here is how to do it:
Method 1: Add Codeberg as a Second Remote
# Check your current remotes
git remote -v
# Add Codeberg as a new remote (usually called "codeberg")
git remote add codeberg https://codeberg.org/your-username/your-repo-name.git
# Push to Codeberg
git push -u codeberg main
Method 2: Change the Default Remote
If you want to switch completely to Codeberg:
# Remove the current origin
git remote remove origin
# Add Codeberg as the new origin
git remote add origin https://codeberg.org/your-username/your-repo-name.git
# Push to the new origin
git push -u origin main
Prerequisites:
1. Create the repository on Codeberg first - Go to codeberg.org and create a new repository with the same name
2. Make sure your local repository is up to date with git pull origin main (if using Method 1)
After Pushing:
- Your project will now be on both GitHub and Codeberg (if using Method 1)
- Or exclusively on Codeberg (if using Method 2)
- You can push to either remote using:
git push origin main # for GitHub
git push codeberg main # for Codeberg
You can check your remote connections using these commands:
Check All Remotes
git remote -v
This shows all configured remotes and their URLs.
Check Specific Remote
git remote show origin
This shows detailed information about the 'origin' remote.
Check Which Branch Tracks Which Remote
git branch -vv
This shows which local branches are tracking which remote branches.
Verify Push/Pull
After running git remote -v, you'll see output like:
origin https://codeberg.org/your-username/your-repo.git (fetch)
origin https://codeberg.org/your-username/your-repo.git (push)
If both lines show your Codeberg URL, then you're successfully connected to Codeberg!
Quick tip: The -u flag in git push -u origin main sets up tracking, so future pushes can just be git push without specifying the remote and branch.
Comments
Post a Comment