This is an old revision of the document!


Git

Installation

The git version control system is installed with the following command:

apt-get install git

Commands

git init                                       #Initialize repository in actual working directory
git config --global user.name "Your Name"      #Set your account's default identity
git config user.name "Your Name"               #Set the identity only in this repository
git status                                     #Show which files tracked
git add file                                   #Add file "file"
git add .                                      #Add all files in working directory
git commit -m "initial commit"                 #Commit all files with comment
git log                                        #Show history
git reset --hard                               #Discard changes which are not commited yet
git revert ID                                  #Revert to change from ID - other changes after not affected
git checkout ID file                           #Revert to change from ID
git diff                                       #Show diff/ changes

Konfiguration

Every git user should first introduce himself to git, by running these two commands:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

Basic usage

The above is already sufficient to use git in a distributed and secure way, provided users have access to the machine assuming the server role via SSH. On the server machine, creating a new repository can be done with:

git init --bare /path/to/repository

Note:This creates a bare repository, that cannot be used to edit files directly. If you would rather have a working copy of the contents of the repository on the server, ommit the –bare option.

Any client with SSH access to the machine can then clone the repository with:

git clone username@hostname:/path/to/repository

Once cloned to the client's machine, the client can edit files, then commit and share them with:

cd /path/to/repository
#(edit some files
git commit -a # Commit all changes to the local version of the repository
git push origin master # Push changes to the server's version of the repository

Remote git

eval $(ssh-agent -s)
ssh-add /home/myuser/.ssh/id_rsa
git remote add gitlab git@git.local:myuser/kubernetes.git            #"gitlab" = name you can choose
git remote add origin ssh://git@hostname:8822/tmade/icinga.git
git remote                                                           #check, if remote location exists (test/ prod)
git remote -v
git remote remove origin                                             #remove remote "origin"
git add .                                                            #or "git add kubeadm-config.yaml"
git commit -m "initial commit"                                       #to the previously created project on e. g. gitlab
git push gitlab master                                               #gitlab target-server
linux/git.1591344161.txt.gz · Last modified: 2020/06/05 10:02 by tmade
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 4.0 International
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki