Git 2 cheatsheet
Git 2: Remotes
6 common Git 2 tasks.
Add a remote
Connect the repository to a remote named origin.
git remote add origin https://github.com/user/repo.git
Fetch without merging
Download new commits from all remotes and drop references to deleted branches.
git fetch --all --prune
Pull with rebase
Fetch and replay your local commits on top, avoiding a merge commit.
git pull --rebase
Push a new branch
Push the branch and set its upstream so later pushes need no arguments.
git push -u origin feature/login
Force push safely
Overwrite the remote branch only if nobody has pushed to it since you last fetched.
git push --force-with-lease
Caution: Force pushing replaces remote history. Never do it on a shared branch such as main.