Skip to content
Git Basics: Practicing Fetch Pull and Push Locally

Git Basics: Practicing Fetch Pull and Push Locally

October 9, 2026

A remote can be another directory on your computer. Use a local bare repository to practice sharing commits without an account, network connection, or changes to a real project.

Run this article in Bash with Git 2.28 or newer and default Git settings. All three repositories stay inside one fresh temporary directory.

Create a remote and first working copy

git_practice=$(mktemp -d) || exit
cd "$git_practice" || exit
git init -q --bare -b main shared.git
git init -q -b main writer
cd writer || exit
git config user.name 'Practice User'
git config user.email 'practice@example.invalid'
git config commit.gpgsign false
printf 'port=8080\n' > app.conf
git add app.conf
git commit -q -m 'Add application config'
git remote add origin ../shared.git
git push -q -u origin main

The bare repository stores Git history without a checked-out working tree. origin is a conventional remote name, and its destination here is a local directory. push sends the commit and updates that remote’s main. -u records the upstream for the local branch.

Identity and signing settings affect only writer; use your own identity in real projects. The temporary files remain afterward.

Clone a second copy

cd "$git_practice" || exit
git clone -q shared.git reader
cd reader || exit
cat app.conf
port=8080

The clone has its own working files and local main branch. It also remembers the remote branch as origin/main.

Push another change

cd "$git_practice/writer" || exit
printf 'port=9090\n' > app.conf
git add app.conf
git commit -q -m 'Change application port'
git push -q origin main

Only the shared repository has received this update. The reader has not fetched it yet.

Fetch before updating files

cd "$git_practice/reader" || exit
git fetch -q origin
cat app.conf
git show origin/main:app.conf
port=8080
port=9090

fetch updates the reader’s knowledge of remote history. Its working file and local branch stay where they were. origin/main is a local record of the remote branch at the last fetch, not a live view of the other repository.

Bring the local branch forward

git pull -q --ff-only
cat app.conf
port=9090

pull fetches and then integrates the upstream into the current branch. Here, --ff-only allows the branch to move forward without a merge commit and refuses if the histories have diverged. This still fetches, even though we just ran fetch separately to see the two steps.

In a real project, inspect local work before pulling. If a push is rejected because the remote has newer commits, fetch and review them; do not reach for force-push as a routine fix.

References

Git fetch manual, Git pull manual, and Git push manual

Acknowledgements

This post was created with assistance from AI.

Last updated on