Remote - GradedJestRisk/git-training GitHub Wiki
A remote is a link (pointer) to another repository:
- can be on the same machine
- can be on another machine, accessed through network, eg. through GitHub account
WARNING: upstream is ambiguous because it also refers to revisions => commit's parents, or branch ancestor.
Overview:
- list:
- general
git remote -v
- detail:
git remote show <REMOTE_NAME>
- general
- add:
git remote add origin <URL>
- change URL:
git remote set-url origin <URL>
Cloning a repository automatically:
- create the remote;
- set the upstream for all existing branches.
.git/config
file
[remote "origin"] url = https://github.com/GradedJestRisk/git-training.wiki.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master
git remote -v
will show the remote's URL:
origin https://github.com/GradedJestRisk/git-training.wiki.git (fetch) origin https://github.com/GradedJestRisk/git-training.wiki.git (push)
git remote show <REMOTE_NAME>
will show the remote's branches:
* remote origin (..) HEAD branch: master Remote branch: master tracked Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (up to date)
git fetch
retrieve all changes on remote branches (including branhce creation).
Fetch can fetch a specific branch on the remote and retrieve it on another branch locally:
git fetch <REMOTE_NAME> <REMOTE_BRANCH_NAME>:refs/remotes/origin/<REMOTE_BRANCH_NAME_ON_LOCAL
- eg:
git fetch origin master:refs/remotes/origin/mymaster
When you create a branch locally, it doesn't exists yet in the remote. If you want to push it, you need to specify in which remote branch to push it.
git branch --set-upstream-to=<remote>/<branch> <branch>
eg. git branch --set-upstream-to=origin/feature feature
git push
updates remote refs using local refs.
Syntax is git push git <REMOTE_NAME> <BRANCH_NAME>
So, updating master
branch on origin
remote is git push origin master
.
If you're already on master branch, and the remote is set for push, this can be shortened to git push
.
If you want to push on another branch, use colon pattern on branch name <SOURCE>:<DESTINATION>
Full syntax is as follows git push git <REMOTE_NAME> <LOCAL_BRANCH_NAME>:<LOCAL_BRANCH_NAME>
.
Example: Push master local branch to qa/master remote branch is git push origin master:refs/heads/qa/master