MaruOpsInfrastructure and AI notes

About (Korean)Contact (Korean)

[Git and GitOps 10] Work with Remotes: clone, fetch, pull and push

Wooden desk with laptop and mug

Reference photo · Wooden desk with laptop and mug · Photo: Ryan Riggins ryan_riggins / Source / CC0 · Resized for listings; illustrative photo, not the tested environment

A remote repository makes committed history available to another computer. origin is a local name for an endpoint, not the name of a Git server product. Distinguish local branches and remote-tracking branches before comparing fetch, pull and push.

For now, the explanation is based on servers that are already available, such as GitHub and existing in-house Git services. The server you will create yourself is prepared in parts 14 and 15. Replace the URL and username with actual values ​​provided by the server; do not put tokens or passwords in the URL.

Git·GitOps All Series · 10 / 24

On this page

Distinguish between new projects and existing local projects

If the project has a history on the server, clone it from an empty work path. The URL below is an example of grammar and will not be accessed as is.

cd ~/git-lab
git clone https://git.example.com/team/project.git
cd project
git remote -v
git branch -vv

If gitops-demo already exists locally, create an empty server repository without a README, then register it as the remote. Creating an initial commit on the server as well gives the two repositories separate starting histories and requires an additional integration decision.

cd ~/git-lab/gitops-demo
git remote add origin https://git.example.com/team/gitops-demo.git
git remote -v
git push -u origin main

-u sets upstream of local main. This is a relationship that will be used as a reference when calling push or pull without any arguments. If you already have an origin, do not repeat add, but check with git remote get-url origin and use set-url if necessary.

fetch is search, pull is integration after search

git fetch origin
git log --oneline --graph --decorate --all -15
git diff main..origin/main
git switch main
git pull --ff-only

origin/main is not a real-time view of the server, but a local remote tracking reference updated during the last fetch. Even if fetch retrieves server history, it does not immediately merge the current working branch. This is useful for comparing first and deciding how to integrate them.

pull performs a fetch followed by a merge or rebase. --ff-only causes it to stop if there is a branched local history. In the stopped state, git status, look at the graph and choose whether to rebase or merge the unshared commit. Do not take clearing tasks with reset --hard origin/main as the first step in resolving the error.

SSH verifies user keys and server keys separately

You can generate user keys in Linux Bash or Git Bash. Use a new name that won’t overwrite the existing file and set a passphrase. Register only the public key .pub in your Git service’s account settings.

mkdir -p ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t ed25519 -C "git-client" -f ~/.ssh/id_ed25519_gitteam

If you have multiple keys, you can specify a server-specific IdentityFile with ~/.ssh/config. Enter the actual server address, account, and port.

Host git-team
    HostName git.example.com
    User git
    Port 22
    IdentityFile ~/.ssh/id_ed25519_gitteam
    IdentitiesOnly yes

The server host key fingerprint that appears when first connecting is compared with the value received through a separate path from the administrator. Just collecting the key with ssh-keyscan does not prove the server’s identity. After reinstalling the server, existing known_hosts entries are not deleted even if a warning occurs.

If push is rejected, see other people’s changes first

non-fast-forward may mean that the end of the server is ahead of where I know it is, or that the history has diverged. Check the difference after fetch. If it’s my unshared commit, I can rebase it, but I avoid pushing and covering the shared main.

symptomsWhat to look at first
DNS·Connection failureServer name, port, VPN, firewall
Permission denied (publickey)SSH user, public key registered, private key in use
HTTPS 401·403Token expiration/scope, storage permissions
non-fast-forwardCommit graph on both sides after fetch

The standard of the command is git fetch, git pull, git push. HTTPS authentication uses the service’s authentication helper or credential store and manages access tokens without leaving the screen and shell history.

Previous · [Git and GitOps 09] Resolve Conflicts with the Common Ancestor and a Three-Way Merge · Next · [Git and GitOps 11] Team Branching and Pull Requests: Merge or Rebase · Series list and example files