Difference between revisions of "Git"

From Zombi Wiki
Jump to navigation Jump to search
m (removing dead link)
(push all the things! ;))
 
(12 intermediate revisions by 4 users not shown)
Line 1: Line 1:
=== Git ===
 
Please always use useful commit messages.
 
 
 
Git is a version control tool for source code and text files.
 
Git is a version control tool for source code and text files.
 
We use it for working on projects together.
 
We use it for working on projects together.
Line 7: Line 4:
 
* [http://git-scm.com/book Official Git-Book]
 
* [http://git-scm.com/book Official Git-Book]
 
* [http://git-scm.com/docs/gittutorial Tutorial]
 
* [http://git-scm.com/docs/gittutorial Tutorial]
* [https://git.zom.bi/ Our Gitlab]
+
* [https://gitea.zom.bi/ Our Gitea]
=== Commiting on the docker-host ===
+
== Commiting on the docker-host ==
 
use the compact alias <code>git ''username''-commit</code> to commit with your user information.
 
use the compact alias <code>git ''username''-commit</code> to commit with your user information.
 
''git-push'' all the changes often, so collaboration becomes easier.
 
''git-push'' all the changes often, so collaboration becomes easier.
  
 
Please always use useful commit messages.
 
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)
 +
<code>
 +
git clone http://XXXXXXXXXXXXXXXXXXXXXXX
 +
</code>
 +
=== Update Repository ===
 +
this updates the changes from the origin (gitlab server)
 +
<code>
 +
git pull
 +
</code>
 +
=== Committing Changes ===
 +
In this example you have created a file ("somefolder/somefile") and edited it
 +
<code>
 +
# if the file is new, add the file to be commited
 +
git add somefolder/somefile
 +
# make a commit of the changes
 +
git commit -m "i made some changes to a new file"
 +
</code>
 +
 +
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
 +
<code>
 +
git push
 +
</code>
 +
 +
=== Status ===
 +
You can check the status of your repostory (list which files have been changed since the last commit)
 +
 +
<code>git status</code>
 +
if nothing has been changed
 +
<code>> git status
 +
Auf Branch master
 +
Ihr Branch ist auf dem selben Stand wie 'origin/master'.
 +
nichts zu committen, Arbeitsverzeichnis unverändert</code>
 +
if you did change something which hasn't been commited yet
 +
<code>> 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")</code>
 +
 +
=== 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|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 remote add gitea "https://gitea.zom.bi/username/project.git"
 +
  # Push to Gitea
 +
  git push -u gitea --all
 +
  git push -u gitea --tags
  
 
[[Category:Documentation]]
 
[[Category:Documentation]]

Latest revision as of 10:45, 15 September 2020

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 remote add gitea "https://gitea.zom.bi/username/project.git"
 # Push to Gitea
 git push -u gitea --all
 git push -u gitea --tags