Basics
We will learn some basic commands to get to know git a little bit better.
git configuration
In order to track contributions in a project we set our user name and our email address. Your name and email will be associate with your commits.
Exercise - git user name
Set up your git user name:
git config --global user.name "first-name last-name"
Replace the placeholders with your first-name and last-name.
Exercise - git user email
Set up your git user email:
git config --global user.email "your-name@company.de"
Replace the placeholder with your email address. Some Git hosting platforms (e.g., GitHub, GitLab) use this to link commits to your account.
Exercise -default text editor
Set your default text editor to Nano:
git config --global core.editor "nano"
This defines which text editor git should use when opening commit messages or rebase instructions. With your favorite text editor set you can edit messages easily if git prompts you for input. Other options are e.g. Vim or VS Code.
Exercise - verification
Now let’s verify that all settings are configured correctly by running:
git config --list --show-origin
Working with git
We will now have an easy start with git by creating our first repository and our first revision.
Exercise - local directory
First create a local directory on your machine:
mkdir git-beginners
You can check if the creation of the directory was successful with the ’ls’ command:
ls
Now navigate to the ‘git-beginners’ directory you’ve just created:
cd git-beginners
Check if you’re in the directory by executing ‘pwd’:
pwd
The ‘pwd’ command displays the directory you’re currently in.
Finally we will initialize a new git repository with ‘main’ as the initial branch name:
git init --initial-branch=main
This marks our git-beginners directory as a git repository and sets up the necessary metadata so git can start tracking changes.
You can also check for the ‘.git’ folder using the following command:
ls -lah
This command will list all the folders and files in your directory (also the hidden ones):
$ ls -lah
total 0
drwxr-xr-x 3 your-user staff 96B Mar 18 12:14 .
drwxr-x---+ 42 your-user staff 1.3K Mar 18 12:06 ..
drwxr-xr-x 9 your-user staff 288B Mar 18 12:14 .gitThe ‘.git’ folder contains all the repository metadata, including commit history, branches, and configuration files.
Exercise - revision
Next we will create our first revision for our repository.
Execute the following command to create your first revision:
echo “My first revision“ >> <your-name>-first-revision.txt
Again with the ’ls’ command you can verify that the file was created.
Now use the ‘add’ command to move your new file from the working directory to the staging area, preparing it for commit.
git add your-name-first-revision.txt
With the ‘status’ command you can verify that the file was added:
git status
Finally we ‘commit’ our file and save it from the staging area to the repository’s history.
git commit --message '<your-name> initial commit'
Optional: Useful git aliases - making future work smoother
To make git commands more efficient, set up aliases:
git config --global alias.logo "log --oneline"
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.cm "commit -m"Verify alias settings:
git config --global --list | grep alias
Instead of using git log --oneline you could now just use your alias git logo.
You are now ready to proceed with the poem exercise The poem - Part 1 .