Log inSign up

The everyday Git loop: clone, commit, push, pull

Copy a project with git clone, edit files, stage them with git add and record a snapshot with git commit -m "message". Send your commits to the shared repository with git push and bring in other people's work with git pull; git status tells you at every step what Git sees.

Topic: Git on a server · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9, AlmaLinux 9 · Updated 2026-12-03

What happens in the three areas Git tracks?

Git keeps every file in one of three places, and each command moves changes between them. The working tree is the folder you edit. The staging area (also called the index) holds the exact changes you picked for the next commit. The repository inside .git stores the commits themselves, each a full snapshot with an author, a date, a message and a pointer to its parent.

A remote such as origin is simply another copy of that repository on a different machine. Nothing travels between your copy and the remote until you run fetch, pull or push, which is why you can commit on a server with no network and sync later. If Git is not installed yet, start with installing and configuring Git.

How do you clone an existing repository?

Pass the remote address to git clone; Git creates a folder, downloads the full history and checks out the default branch.

# over SSH (needs your public key on the Git host)
git clone git@git.example.net:team/app.git

# over HTTPS into a chosen folder
git clone https://git.example.net/team/app.git /srv/app

cd app
git remote -v
git log --oneline -5

git remote -v shows the fetch and push addresses of origin. For a very large project where you only need the current files, a shallow clone saves time and disk: git clone --depth 1 URL. You can deepen it later with git fetch --unshallow. To start a brand new project instead, run git init in an empty folder and connect a remote later with git remote add origin URL.

How do you see what changed?

Run git status first, every time; it lists modified, staged and untracked files and says how far your branch is ahead of or behind the remote.

git status
git status -s          # short two-column form
git diff               # unstaged changes, line by line
git diff --staged      # what the next commit will contain
git log --oneline --graph -10

In the short form the left column is the staging area and the right column the working tree, so M means staged and M means edited but not yet staged. ?? marks a file Git has never tracked.

How do you stage and commit work?

Stage the files you want with git add, then turn the staged set into a commit with a clear message.

git add config/app.ini              # one file
git add src/                        # a whole folder
git add -p                          # pick hunks interactively
git commit -m "Raise worker count to 4"

git add -p walks through each changed block and asks whether to include it, which keeps unrelated edits out of a commit. git commit -a -m "..." stages every tracked, modified file in one go but skips new files. Good commit messages start with a short summary line under about 70 characters in the imperative mood ("Fix", "Add", "Remove"), then a blank line and any details. If you forgot a file in the commit you just made and have not pushed yet, stage it and run git commit --amend --no-edit.

Which files should stay out of the repository?

Secrets, build output and machine-specific files belong in .gitignore, a plain list of patterns at the top of the repository.

cat > .gitignore <<'EOF'
.env
*.log
node_modules/
vendor/
__pycache__/
/storage/cache/
EOF
git add .gitignore
git commit -m "Ignore secrets, logs and dependencies"

Ignoring a file only affects untracked files. If a secret was committed already, git rm --cached .env stops tracking it, but the old commits still contain it, so rotate that password or key. Keep runtime settings in environment variables or an untracked file instead.

How do you push commits to the remote?

git push uploads the commits your branch has that the remote branch lacks. The first push of a new branch needs the upstream link, after which a bare git push is enough.

git push -u origin main     # first time: link local main to origin/main
git push                    # afterwards

If the push is rejected with "fetch first" or "non-fast-forward", someone else pushed in the meantime. Do not force it; pull their work, resolve anything that clashes and push again. Forced pushes rewrite shared history and are covered with their safer --force-with-lease form in the rebase guide.

How do you pull other people's changes?

git pull is a git fetch followed by a merge (or a rebase, depending on pull.rebase) of the remote branch into yours.

git pull
# or, in two steps so you can look first:
git fetch origin
git log --oneline main..origin/main
git merge origin/main

The two-step form is useful on production servers: you read what is about to arrive before it touches the checkout. For a deploy-only clone that should never hold local commits, git pull --ff-only refuses anything except a clean fast-forward, which turns a surprise into an error instead of an accidental merge commit.

What do you do when a pull ends in a conflict?

Git stops and marks the clashing lines in the affected files; you edit them to the right final text, stage them and finish the merge.

git status                    # lists "both modified" files
nano config/app.ini           # remove the markers, keep the right lines
git add config/app.ini
git commit                    # completes the merge

The markers look like a line of <<<<<<<, your version, a line of =======, their version and a closing >>>>>>> line. Remove all three marker lines. If you would rather start over, git merge --abort returns to the state before the pull. The undo guide covers more ways back.

How do you mark releases with tags?

A tag is a fixed name for one commit, ideal for version numbers you deploy. Annotated tags carry a message and the tagger, so prefer them for releases.

git tag -a v1.4.0 -m "Release 1.4.0"
git push origin v1.4.0
git tag --list "v1.*"
git checkout v1.4.0           # look at that release (detached HEAD)

Tags are not pushed by a normal git push; push them by name or with git push --tags. A server that deploys by tag can run git fetch --tags and check out the release it needs.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-1enough for clones and small projects1 vCPU, 1 GB RAM, 25 GB NVMe$3.60/mo$43.20 for 12 months

Questions about Clone, commit, push and pull

What is the difference between fetch and pull?

git fetch only downloads new commits and updates origin/main; your files stay untouched. git pull fetches and then merges or rebases those commits into your current branch.

Why does git push ask for a username and password?

The remote uses HTTPS. Switch it to SSH with git remote set-url origin git@git.example.net:team/app.git, or use an access token with a credential helper as described in the install guide.

How do I see who changed a line?

Run git blame path/to/file. Each line shows the commit, author and date of its last change; git show COMMIT then displays that full commit.

Can I work on the server directly in a clone used by the website?

It works, but edits made in a live checkout are easy to lose and hard to review. Commit on your own machine or in a separate clone, push, and let the server pull or receive the push, as in the deploy hooks guide.

How do I remove or rename a tracked file?

Use git rm file or git mv old new and commit. Both stage the change for you, so the next commit records the removal or the rename.