The Codeberg Documentation website is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
It bundles third-party font software licensed under a different license. Please look at the LICENSE file for details.
Changes to the original versions of the article as well as its individual authors can be looked up in this article's commit history
Codeberg and the Codeberg Logo are trademarks of Codeberg e.V.
Almost everything on Codeberg happens in a repository. Think of a repository as a home for your project, where all of its source code can be organized using Git, as well as where you can track issues and read and write wikis.
This article will guide you through creating your first repository on Codeberg, connecting your local development environment and making your first commit.
Note for advanced users: The Push To Create feature is disabled on Codeberg.
To create a new repository, you need to log in to your account on Codeberg.
When you're logged in, you can use one of the two buttons shown in the two following screenshots to create a new repository:
This will lead you to this page below.
Here's an explanation of the form's fields:
https://codeberg.org/knut/foobar
)LICENSE
file will then be added to the repository. For some help on choosing the correct license, have a look at our licensing article.LICENSE
, README
and .gitignore
files mentioned above to your new repository, make sure you tick this box.If you have code locally you wish to add do NOT allow Codeberg to add any files to the repository. To prevent this, ensure the option
[]-Initialize repository (Adds .gitignore, LICENSE and README)
is not checked. If Codeberg creates files, you will end up with two repositories without any shared history and Codeberg will refuse to sync them until you resolve the 'conflicts' manually. Instead, see Option B below.
It's okay to only specify owner and repository name, if you want to get started quickly. After filling out the fields, click the green "Create Repository" button on the bottom of the page.
You should now see a screen similar to the one below. If you haven't chosen to generate LICENSE
, README
and .gitignore
the screen might show instructions instead, which will vanish after your first commit.
Here's what the most important buttons here do:
After creating a new repository, as laid out in the previous section, you can now move on to connect the repository with your local development copy.
In this guide, we'll focus on connecting to Codeberg via HTTP using Git on the command line, but note that there are multiple other ways to connect to Codeberg, as laid out in more detail in the articles:
Although we use HTTP in this Getting Started guide, it is a good idea to setup SSH-based authentication once you feel confident to do so.
If you want to start a fresh project (so if you don't already have source code that you want to upload to Codeberg), the quickest way to get started is to clone your newly created repository like this:
If you're just getting started, it's a good idea to keep your projects neatly sorted in a dedicated directory, like in this example:
knut@iceberg:~$ mkdir repositories
knut@iceberg:~$ cd repositories
knut@iceberg:~/repositories$
To clone your newly created repository, execute git clone
with the URL that is shown in your repository:
knut@iceberg:~/repositories$ git clone https://codeberg.org/knut/foobar
Cloning into 'foobar'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), 11.94 KiB | 764.00 KiB/s, done.
After cloning, the repository should now be in a new directory with the same name as your repository. In this case, it's called foobar
.
knut@iceberg:~/repositories$ cd foobar
knut@iceberg:~/repositories/foobar$ ls
LICENSE README.md
If you already have written source code that you now would like to upload to Codeberg, follow these steps:
Unless you already have a Git Repository initialized in your local source tree,
run git init
in your project's directory:
knut@iceberg:~/my-project$ git init
Initialized empty Git repository in /home/knut/my-project/.git/
git checkout -b main
You need to add files before committing them. Suppose you have a local file already-written.tex
.
git add already-written.tex
For Option B, your first commit must be local to avoid conflicts. This is why we prevented Codeberg from adding any files above.
git commit -m "first commit"
Now, you need to tell Git where to push your changes. You would do that by specifying Codeberg as a remote.
In this example, we'll specify Codeberg as the origin
remote. You can name your remote any other way, especially if you already have an origin
, but origin
is the recommended name for the main remote repository.
knut@iceberg:~/my-project$ git remote add origin https://codeberg.org/knut/foobar
When you clone a repository from the Internet, the URL that you got your copy of the repository from will be automatically used for the origin
remote.
git push -u origin main
Now your Codeberg repository shares a common history with your local repository, you can make changes to either and use git
to manage them.
Codeberg does not provide an interface to add licence files, .gitignore
or README.md
retrospectively, so you should add at least the licence and README.md
yourself.
Now that you've connected your repository to your local development copy, it's time to make your first commit.
If you didn't generate the
LICENSE
andREADME.md
files when creating the repository, it's a good idea to add them now. Just put them in your local development copy's directory and add them to your commit, as shown below.
Let's modify the README.md
file.
If you didn't generate
README.md
, these commands will still work fine. However, instead of "Hello World!" being at the end of the file, it'll be the only line in the file.
knut@iceberg:~/repositories/foobar$ echo "Hello World!" >> README.md
knut@iceberg:~/repositories/foobar$ cat README.md
# foobar
Hello World!
Now, if you now ask Git about your repository's status, you should see something similar to this:
knut@iceberg:~/repositories/foobar$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
You can create or modify more files, if you'd like.
Next, you should add each modified file that you'd like to add to your commit with git add
:
knut@iceberg:~/repositories/foobar$ git add README.md
This command should output nothing.
If you want to add all modified files in your source tree, you can run
git add .
but be careful as this might add unwanted files as well, so it's a good idea to double-check by runninggit status
before committing.
By committing your changes, you create a new step in the version history of your program. They act like snapshots of your program's state at a given point of time, and you will later be able to jump back and forth between them.
It is recommended to keep commits small and focused, so that, if necessary, they can be reverted or easily adapted into another context without too many side-effects.
To commit your changes, run git commit
and specify a commit message; this will later help you (and others) to identify that commit when looking back at your version history.
knut@iceberg:~/repositories/foobar$ git commit -m "My first commit on Codeberg"
[main 1e12979] My first commit on Codeberg
1 file changed, 1 insertion(+)
If you look at the version history of your program using git log
, you may now see something similar to this:
knut@iceberg:~/repositories/foobar$ git log
commit 1e1297929c8c74d9a439fa71c1f0ffe1dbf3d5ad (HEAD -> main)
Author: Knut <knut@noreply.codeberg-test.org>
Date: Sat Sep 26 14:01:00 2020 +0200
My first commit on Codeberg
commit c75b50920e3aa7a7ab3484e898fb3ad77132722a (origin/main, origin/HEAD)
Author: Knut <knut@noreply.codeberg-test.org>
Date: Sat Sep 26 12:29:57 2020 +0200
Initial commit
If you're happy with the changes you made, the next step is to present them to the world by pushing them to Codeberg:
knut@iceberg:~/repositories/foobar$ git push -u origin main
Username for 'https://codeberg.org': knut
Password for 'https://knut@codeberg.org':
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 315 bytes | 315.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: . Processing 1 references
remote: Processed 1 references in total
To https://codeberg.org/knut/foobar
c75b509..1e12979 main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
If your local copy of the repository is missing some commits that exist in the remote repository, pushing will result in an error. There are two ways to fix this:
git pull
to combine your local changes with the changes that exist in the remote repository. If this does not work, please follow the instructions in your terminal.git -f push
.
This action will permanently alter your remote repository and is not suitable if you are working on a project together with other people.The -u
option sets the upstream remote, which we want to be Codeberg.org, as configured previously.
The main
argument sets the name of the branch onto which shall be pushed upstream. For this example, it should be the same branch name that you specified when creating the repository.
When connecting via HTTPS, Git will ask you for your username and password, which you can enter interactively.
After refreshing the repository page, you should now see something similar to this:
Congratulations - you've just made your first source code contribution on Codeberg!
If you want to promote your work you can use Codeberg's Badge Generator to easily generate a badge which links to you repository.
In the badge generator you can edit how the badge should appear. Mainly this is:
Just add the following line as markdown to the site you want to link from:
[![Get it on Codeberg](your-badge.png)](https://codeberg.org/your-username/your-repo)
or in HTML:
<a href="https://codeberg.org/your-username/your-repo">
<img src="your-badge.png" alt="Get It On Codeberg" width="250" />
<a
/></a>
This will result in a badge like this:
Now, you should learn more about issue tracking.
Hey there! 👋 Thank you for reading this article!
Is there something missing, or do you have an idea on how to improve the documentation? Do you want to write your own article?
You're invited to contribute to the Codeberg Documentation at its source code repository, for example, by adding a pull request or joining in on the discussion in the issue tracker.
For an introduction on contributing to Codeberg Documentation, please have a look at the Contributor FAQ.
© Codeberg Docs Contributors. See LICENSE