Extra part: First steps

Requirements

Git must be installed and can be downloaded here for almost all operating systems or is usually already part of your favorite distribution. Under FreeBSD e.g. a pkg install git or under Debian an apt install git is sufficient.

Attention, these steps only work if the 2FA authentication is not yet activated. If this is the case for you, then the specification with the username/password is not sufficient and we need additional steps.

However, the diversity of Git is much higher, especially when it comes to simultaneous local and online edits. But there are many more online resources.

Last updated:

  • 05.01.2024: Various minor adjustments
  • 20.05.2023: Initial document

Create empty project

New system, new luck. The first repository is quickly created.
However, in order to be able to use it online directly to its full extent, Initialization must be activated during creation.

new initialization

Only with this, files can then be created or uploaded directly after the project creation via the Gitea page in the browser and then edited.

Set up local git

If the files created online from a repository are to be edited locally after all, they can be downloaded. A repository always needs a dedicated folder locally, where the configuration and the files are stored.
For this, the following steps are necessary once:

mkdir REPOSITORYNAME
cd REPOSITORYNAME
git init
git config user.email "EMAIL"
git config user.name "NAME"
git remote add origin http://GITEAIP:3000/USERNAME/REPOSITORYNAME.git

This creates:

  • create and prepare the REPOSITORYNAME folder for git (mkdir REPOSITORYNAME, cd REPOSITORYNAME, git init) ,
  • set the name/email of the author (git config user.email "EMAIL", git config user.name "NAME") ,
  • set the target as alias origin (git remote add origin http://GITEAIP:3000/USERNAME/REPOSITORYNAME.git) ,

Download files

cd REPOSITORYNAME
git pull origin main

This will download:

  • All files from the source origin and the main branch main are downloaded (git pull origin main), at the first time also username and password are requested. main is the current working version, so to speak. To keep the local files always up to date it is sufficient to repeat git pull origin main in the folder REPOSITORYNAME before updating files locally.

Upload files

If there were local changes, they will be uploaded back to the git after editing.
The three commands are always necessary for this:

git stage .
git commit -m "COMMENT"
git push origin main

This will:

  • All local changes are made known (git stage .), alternatively this can be only one file (git stage FILE).
  • Each change is documented by a comment (git commit -m "COMMENT")
  • Then everything is uploaded to the target origin in the branch main (git push origin main)

Migration of existing files

Let's say there is an existing directory on your machine that you want to migrate to Git.
For this it is sufficient to create a new repository, but here you should do it without the initialization, .....

new

... which is waiting for the first "contents".

Make local files and git known

On your computer, change to the directory with the existing files via console and follow these commands:

cd REPOSITORYNAME
git init
git config user.email "EMAIL"
git config user.name "NAME"
git remote add origin http://GITEAIP:3000/USERNAME/REPOSITORYNAME.git

This will prepare:

  • prepare the REPOSITORYNAME folder for git (cd REPOSITORYNAME, git init) ,
  • set the name/email of the author (git config user.email "EMAIL", git config user.name "NAME") ,
  • set the target as alias origin (git remote add origin http://GITEAIP:3000/USERNAME/REPOSITORYNAME.git) ,

Initial file upload

git checkout -b main
git add .
git commit -m "First commit"
git push origin main

This will:

  • all files in the folder are made known (git checkout -b main, git add .) ,
  • files with a comment (git commit -m "COMMENT"), so that they are versioned and changes are documented
  • and uploaded to the target origin branch main (git push origin main)

Then the repository is also fully usable online.
In the example, my test directory contains only a single README.md file.

repository

For further changes, the steps described above are necessary to [upload](#upload files) or [download](#download files) files.

Voilá