Skip to main content

Git basics

Quick setup

Configure git

#
# Set user name and e-mail
# Change the default branch from master to main
# Store main repoitory hoster (like github) user credentials globally on next pull/push action
#
git config --global user.name "Mein Name"
git config --global user.email meine.mail@domain.de
git config --global init.defaultBranch main
git config --global credential.helper store

Create a new repository on the command line

#
# Assumes an empty Repository named my-repository on e.g. github.com
#
echo "# my-repository" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/rastef/my-repository.git
git push -u origin main

Push an existing repository from the command line

#
# Assumes an empty Repository named my-repository on e.g. github.com
#
git remote add origin https://github.com/rastef/my-repository.git
git branch -M main
git push -u origin main