Skip to content

Latest commit

 

History

History
103 lines (79 loc) · 2.78 KB

File metadata and controls

103 lines (79 loc) · 2.78 KB

Git Remotes

Remotes are versions of your project that are hosted on the internet or network somewhere. These commands allow you to collaborate with others by syncing your local repository with the remote servers.

Add a remote

Connects your local repository to a remote server. Usually the first remote is called origin.

git remote add origin $remote_url

Initial Push

The very first time you push your code, you need to set the upstream tracking branch using -u.

git push -u origin main

Pull changes from remote branch

Pulling fetches the data from the remote server and automatically tries to merge it into your current working code.

git pull $remote $remote_branch

Push current branch to remote

When you have local commits that you want to share, you push them upstream. If you've rewritten history (like via a rebase), you may need to force push. --force-with-lease is a safer alternative to --force that ensures you don't overwrite someone else's work blindly.

git push $force $remote $branch

Fetch changes from remote

Fetching downloads the objects and refs from the remote repository, but does not merge them into your local branches. It is a completely safe operation to see what others have been working on.

git fetch $remote

Rename a remote

git remote rename $remote $new_remote

Change remote URL

Update the URL for an existing remote (e.g. switching from HTTPS to SSH).

git remote set-url $remote $remote_url

Prune deleted remote branches

Removes local references to remote branches that have been deleted on the server.

git remote prune $remote