Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Clone a repository
git clone copies a whole repository with its history and sets the remote origin.
git clone git@github.com:s0sta/infra-shop.git
git clone --depth 1 https://github.com/s0sta/it-notes.git
cd infra-shop && git remote -v
origin git@github.com:s0sta/infra-shop.git (fetch)
origin git@github.com:s0sta/infra-shop.git (push)Onthoud
Use SSH URLs (git@github.com:…) with a key, or HTTPS with a token. Passwords do not work on GitHub any more.
Manage remotes
A repository can have several remotes — for example origin (your fork) and upstream (the original project).
Fetch and pull
fetch downloads new commits but changes nothing in your branch. pull = fetch + merge (or rebase) into your branch.
| Command | Changes your branch? |
|---|---|
git fetch | No, only origin/… |
git pull | Yes, merges origin/BRANCH |
git pull --rebase | Yes, puts your commits on top of the new ones |
Push your branch
git push sends your commits. The first push of a new branch sets the upstream with -u.
git push -u origin feature/web-network
git push
git push origin --delete feature/old
git push --tags
git push --force-with-leaseLet op
--force overwrites the remote branch and can delete others' commits. If you must rewrite a pushed branch (your own feature branch), use --force-with-lease — it refuses when someone else pushed meanwhile.
Understand tracking branches
A local branch can track a remote branch. Then git status tells you if you are ahead or behind.