Comp:git

From Theochem
Revision as of 09:54, 2 March 2024 by Gerritg (talk | contribs) (git init)
Jump to navigationJump to search

To share your software you can use our gitlab server. Extensive documentation for git is available online, see e.g. git tutorial.

Here are instructions to set up a git repository on disk. This is not only useful to share your software or develop software together, it also lets you keep track of versions of you scripts or programs, and synchronize projects between, e.g., a laptop and a desktop computer.

Create .gitconfig

In your home directory create a file with the name .gitconfig with the content:

 [user]
         name = Firstname M. Lastname
         email = username@science.ru.nl

This is all that is needed, but more settings can be added:

 [init]
         defaultBranch = main            # change the default branch name "master" to "main"
 [color]
          ui = auto
 [core]
          pager = more                   # or less
 [diff]
          tool = vimdiff                 # if you use vi or vim
 [alias]
          log1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
          log2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all

Start a new project

Here we give an example of creating a git repository with a single bash script. First create a directory with the script:

  mkdir hworld
  cd hworld
  cat <<EOF > hw.sh
  #!/bin/bash
  echo "hello world"
  EOF
  chmod +x hw.sh
  ./hw.sh              # see if it works

Next, initialize git

  git init             # this creates a subdirectory .git where git keeps info
  git add hw.sh        # we want to use git to keep track of this file, it will be added to the "staging area"
  git commit