git: command line
Create new repository
Create a ~/.gitconfig
configuration file, see below.
Create a local repo
In this example HeNO
is the name of the project:
cd # go to home directory ~
git init HeNO # the name is not part of the repo, can be changed
cd HeNO
echo "He-NO" > molecule.txt # create some file
git add molecule.txt
git commit # starts editor; alternative: git commit -m message
git branch # verify we are in the ``main`` branch
git log2 # if `log1` is defined in .gitconfig
Next, we create a remote “bare” repo, and then we come back here.
Create a remote bare repo
Setup ssh
public/private keys to have access to the remote server. Here we
assume the bare repo is on user@lilo.science.ru.nl:repos
:
ssh user@lilo.science.ru.nl:repos # go to where you want to create the bare repo
git init --bare HeNO # HeNO, same name as local repo for convenience
That’s all
Push local repo to remote repo
Go back to the directory with the local HeNO
repo:
cd ~/HeNO # the local git repo is in the hidden .git directory
git remote add origin user@lilo.science.ru.nl:repos/HeNO
git remote -v # check your command
# if you need to change it:
git remote set-url origin user@lilo.science.ru.nl:repos/HeNO
# copy repo to remote location and remember its name:
git push --set-upstream origin main # next time you'll just need: git push
Use the repo from another computer, e.g. your laptop
Make sure ssh
is configured to let you access the remote server without
password. Also, create a ~/.gitconfig
file, see below.
To get the HeNO
repo:
git clone user@lilo.science.ru.nl:repos/HeNO # copy the repo to local device
cd ~/HeNO
git log2 # have a look
Updating the repo
After editing some files, we can check what has changed and update the repo:
cd ~/HeNO # assume this is where the local repo is
vi molecule.txt # edit a file
vi mol.dat # create a new file
git status # show new and changed files
git diff molecule.txt # see what has changed (using vimdiff if configured below)
git add mol.dat
git commit
git ls-files # list all files in repo
Git commit messages
The first line is a short summary, it starts with feat:
or one of these:
feat: A new feature
fix: A bug fix
docs: Documentation only changes
style: Changes that do not affect the meaning of the code (white-space, semicolumn etc)
refactor: A code change that neither fixes a bug nor adds a feature
perf: A code change that improves performance
test: Adding missing or correcting existing tests
chore: Changes to the build process and libraries such as documentation generation
[empty line]
[Body of the commit message]
Git configuration file
Put this in ~/.gitconfig
:
[init]
defaultBranch = main # instead of master
[user]
name = Firstname and Lastname
email = user@domein.nl
[color]
ui = auto
[pager]
status = true
[core]
pager = more # or "less"
[diff]
tool = vimdiff # if "vim" is your favorite editor
[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
[safe]
directory = /srv/www/htdocs # I trust this directory for remote repo
[filter "indent"]
clean = filter.clean
smudge = filter.smudge