1. Remote Repositories and Synchronization
git remote -vWhat it doesDisplays the names and addresses of the remotes registered for the repository (fetch and push)
When to use itto check the associated remote servers
Example
git remote -vgit remote add origin <url>What it doesLink the local repository to a new remote repository named origin
When to use itWhen a new local repository is uploaded to GitHub for the first time
Example
git remote add origin git@github.com:user/repo.gitgit fetch originWhat it doesFetch all updates and branches from remote without merging them into your local branch
When to use itTo see what is new on the server safely and without surprises
Example
git fetch origingit pullWhat it doesFetches updates and automatically merges them into the current branch
When to use itto update the regular local branch
Example
git pullgit pull --ff-onlyWhat it doesFetch and update the branch only if it can be Fast-Forward updated without creating a merge commit
When to use itTo maintain the cleanliness and integrity of the history of the local branch
Example
git pull --ff-onlygit pull --rebase origin mainWhat it doesFetches and reapplies local changes over the latest update of the remote branch
When to use itbefore payment to avoid unnecessary merge commit
Example
git pull --rebase origin maingit pushWhat it doesUploads local commits to remote branch
When to use itto publish edits after commits
Example
git pushgit push -u origin <branch>What it doesAutomatically raises the branch and sets upstream tracking
When to use itWhen a new branch is first pushed to the remote
Example
git push -u origin feature/logingit push --force-with-leaseWhat it doesA safer version of force push that checks for changes you did not see before replacing remote history
When to use itAfter rebase or commit --amend on your own branch
Example
git push --force-with-lease origin feature/login