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:
git --versionConfigure your identity:
git config --global user.name "Your Name"git config --global user.email "your-name@stratorys.com"Set the default branch name:
git config --global init.defaultBranch mainDocs:
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 commitTask 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.txtTask 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 READMETask 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.txtTask 6: Resolve a merge conflict
Material:
Run these commands to create two branches that edit the same file:
git checkout -b branch-aecho "Version A" > conflict.txtgit add conflict.txtgit commit -m "feat: add conflict.txt from branch-a"git checkout maingit checkout -b branch-becho "Version B" > conflict.txtgit add conflict.txtgit commit -m "feat: add conflict.txt from branch-b"git checkout maingit merge branch-aNow try to merge branch-b:
git merge branch-bGit 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
0Task 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:
cd ..git clone git@github.com:<you>/git-practice.git git-practice-2cd git-practice-2echo "Change from second clone" >> hello.txtgit add hello.txtgit commit -m "feat: add line from second clone"git pushcd ../git-practiceGoal: Pull the remote changes into your original ~/git-practice repo.
Docs:
Expected output:
> tail -1 hello.txt
Change from second cloneTask 9: Read history
Goal: Answer these two questions using Git commands:
- Who last edited each line of
hello.txt? - 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 READMECleanup
Delete practice branches:
git branch -d feat/add-readme branch-a branch-bYou now know enough Git to work at Stratorys. See the Git workflow and Semantic commits references for team conventions.