Git

From Zombi Wiki
Revision as of 10:40, 1 August 2020 by Madmaurice (talk | contribs) (migration gitlab to gitea)
Jump to navigation Jump to search
     
Gitlab

status: stable

Description Version Control tool
URL  https://git.zom.bi
Maintainer  User:Madmaurice
Authentication  LDAP

Git is a version control tool for source code and text files. We use it for working on projects together.

Commiting on the docker-host

use the compact alias git username-commit to commit with your user information. git-push all the changes often, so collaboration becomes easier.

Please always use useful commit messages.

Basics

This is a guide that bsod wrote as a quick overview for the colleagues at work.

Clone

creates a local copy of the repository including all branches (for initial setup) git clone http://XXXXXXXXXXXXXXXXXXXXXXX

Update Repository

this updates the changes from the origin (gitlab server) git pull

Committing Changes

In this example you have created a file ("somefolder/somefile") and edited it

  1. if the file is new, add the file to be commited

git add somefolder/somefile

  1. make a commit of the changes

git commit -m "i made some changes to a new file"

if you change this file you don't need the git add command the next time.

Push committed changes to server

unlike svn files are not uploaded to the server on commit. run the following command in order to push code to the server git push

Status

You can check the status of your repostory (list which files have been changed since the last commit)

git status if nothing has been changed > git status Auf Branch master Ihr Branch ist auf dem selben Stand wie 'origin/master'. nichts zu committen, Arbeitsverzeichnis unverändert if you did change something which hasn't been commited yet > git status Auf Branch master Ihr Branch ist auf dem selben Stand wie 'origin/master'. Änderungen, die nicht zum Commit vorgemerkt sind:

 (benutzen Sie "git add <Datei>...", um die Änderungen zum Commit vorzumerken)
 (benutzen Sie "git checkout -- <Datei>...", um die Änderungen im Arbeitsverzeichnis zu verwerfen)
       geändert:       bind/Dockerfile

keine Änderungen zum Commit vorgemerkt (benutzen Sie "git add" und/oder "git commit -a")

Branching

Create a Branch

a) just create a branch

 git branch branchname

b) create a branch and switch to it automatically (recommended)

 git checkout -b branchname

Switch to a different Branch

switches to another existing branch ("another-branch")

 git checkout another-branch

Delete a branch

a) delete a local branch

 git branch -d branchname

b) delete a remote branch on origin

 git push origin :branchname

Revert Files

sometimes it is necessary to revert files to the status which is in git (because you broke something or edited a file while being in the wrong branch for example)

revert a single file

 git checkout -- filename

revert the whole repository to the status of the last commit.

 git reset --hard

Migrate a project from GitLab to Gitea

Create your project on Gitea here: https://gitea.zom.bi/repo/create

 # Clone using the --mirror flag (It will clone all branches into a bare repo)
 git clone --mirror https://git.zom.bi/username/project.git
 # Add new remote
 git remove add gitea "https://gitea.zom.bi/username/project.git"
 # Push to Gitea
 git push -u gitea