Skip to content

Journey: Git from zero

After this journey you can: create repositories, commit changes, work with branches, handle merge conflicts, push to GitHub, and read history. You'll be comfortable with the daily Git workflow at Stratorys.

This journey does not cover: Git internals, advanced rebase strategies, or submodules.

How to use this page: Each task gives you a goal and links to relevant documentation. Read the docs, figure out the commands, and compare your result with the expected output. Complete the tasks in order - each one builds on the previous state.

Setup

Verify Git is installed:

bash
git --version

Configure your identity:

bash
git config --global user.name "Your Name"
bash
git config --global user.email "your-name@stratorys.com"

Set the default branch name:

bash
git config --global init.defaultBranch main

Docs:


Task 1: Create a repository

Goal: Create a new directory ~/git-practice and initialize it as a Git repository.

Docs:

Expected output:

> git status
On branch main

No commits yet

nothing to commit

Task 2: Make your first commit

Goal: Create a file hello.txt containing Hello Git. Stage it and commit with the message feat: add hello.txt.

INFO

Git tracks changes in three areas: working directory (files on disk), staging area (changes marked for the next commit), and repository (committed history).

Docs:

Expected output:

> git log --oneline
xxxxxxx feat: add hello.txt

Task 3: Modify and commit

Goal: Add a second line This is my Git practice repo. to hello.txt. Check what changed, then stage and commit with the message docs: add description to hello.txt.

Docs:

Expected output:

> git log --oneline
xxxxxxx docs: add description to hello.txt
xxxxxxx feat: add hello.txt
> git diff
(no output - everything is committed)

Task 4: Branch and commit

Goal: Create a new branch feat/add-readme, switch to it, create a file README.md with the content # Git Practice, and commit with the message docs: add README.

Docs:

Expected output:

> git branch
* feat/add-readme
  main
> git log --oneline -1
xxxxxxx docs: add README

Task 5: Merge a branch

Goal: Switch back to main and merge feat/add-readme into it.

Docs:

Expected output:

> git branch
  feat/add-readme
* main
> ls README.md
README.md
> git log --oneline
xxxxxxx docs: add README
xxxxxxx docs: add description to hello.txt
xxxxxxx feat: add hello.txt

Task 6: Resolve a merge conflict

Material:

Run these commands to create two branches that edit the same file:

bash
git checkout -b branch-a
bash
echo "Version A" > conflict.txt
bash
git add conflict.txt
bash
git commit -m "feat: add conflict.txt from branch-a"
bash
git checkout main
bash
git checkout -b branch-b
bash
echo "Version B" > conflict.txt
bash
git add conflict.txt
bash
git commit -m "feat: add conflict.txt from branch-b"
bash
git checkout main
bash
git merge branch-a

Now try to merge branch-b:

bash
git merge branch-b

Git reports a conflict.

Goal: Open conflict.txt, resolve the conflict, remove all conflict markers, and complete the merge with the message fix: resolve merge conflict in conflict.txt.

WARNING

Conflict markers look like <<<<<<<, =======, and >>>>>>>. All three must be removed from the file before you commit.

Docs:

Expected output:

> git log --oneline -1
xxxxxxx fix: resolve merge conflict in conflict.txt
> grep -c "<<<" conflict.txt
0

Task 7: Push to a remote

Goal: Create a new private repository on GitHub (without a README), add it as a remote called origin, and push your main branch.

INFO

You need an SSH key configured for GitHub. See Connecting to GitHub with SSH.

Docs:

Expected output:

> git remote -v
origin  git@github.com:<you>/git-practice.git (fetch)
origin  git@github.com:<you>/git-practice.git (push)

Task 8: Pull a teammate's change

Material:

Simulate a teammate by cloning your repo to a second directory:

bash
cd ..
bash
git clone git@github.com:<you>/git-practice.git git-practice-2
bash
cd git-practice-2
bash
echo "Change from second clone" >> hello.txt
bash
git add hello.txt
bash
git commit -m "feat: add line from second clone"
bash
git push
bash
cd ../git-practice

Goal: Pull the remote changes into your original ~/git-practice repo.

Docs:

Expected output:

> tail -1 hello.txt
Change from second clone

Task 9: Read history

Goal: Answer these two questions using Git commands:

  1. Who last edited each line of hello.txt?
  2. Which commit added README.md?

Docs:

Expected output:

> git blame hello.txt
xxxxxxx (Your Name ...) Hello Git
xxxxxxx (Your Name ...) This is my Git practice repo.
xxxxxxx (Your Name ...) Change from second clone
> git log --oneline --diff-filter=A -- README.md
xxxxxxx docs: add README

Cleanup

Delete practice branches:

bash
git branch -d feat/add-readme branch-a branch-b

You now know enough Git to work at Stratorys. See the Git workflow and Semantic commits references for team conventions.