My usual workflow when working with git, is something like this:
Now, however, I want to be able to push
and pull
from this remote repository without having to specify where I'm pushing to or pulling from; I want my local master to track the remote master.
The proper way to do this isn't clear to me, and I've been unable to determine it from the documentation, even though it shouldn't really be more than one command.
Because it's something that's only ever done once per repository, I've generally employed one of two simple, but hacky, solutions:
git clone
to make a new local repository, and deleted the old one. After git cloning, the new repository is setup to track the origin.I think I should be able to run a command, probably some form of git remote
to setup an existing repository to have master track a remote master. Can anyone tell me what that command is?
When you're publishing a local branch. You can tell Git to track the newly created remote branch simply by using the -u flag with "git push".
line 1: 'git branch -r' (followed by 'git remote update' to update the info on changes to remote) lists all remote branches; 'egrep -vw' is used to knock entries having HEAD and master in the result. line 3: Track the named remote branch while checking it out locally.
To view your remote branches, simply pass the -r flag to the git branch command. You can inspect remote branches with the usual git checkout and git log commands. If you approve the changes a remote branch contains, you can merge it into a local branch with a normal git merge .
You can check tracking branches by running the “git branch” command with the “-vv” option. We can set the upstream branch using the “git push” command. $ git push -u origin branch Total 0 (delta 0), reused 0 (delta 0) * [new branch] branch -> branch Branch 'branch' set up to track remote branch 'branch' from 'origin'.
Use the set-upstream arg:
git branch --set-upstream local-branch-name origin/remote-branch-name
Running the above command updates your .git/config file correctly and even verifies with this output:
"Branch local-branch-name set up to track remote branch remote-branch-name from origin."
EDIT: As martijn said: "In version Git v1.8.0, --set-upstream is deprecated. Use --set-upstream-to instead."
git branch --set-upstream-to local-branch-name origin/remote-branch-name
See this for more information.
git help remote
should show you what you need to know. I think what you want is
git remote add [remote-name] [remote-url] # Set a local branch to follow the remote git config branch.[branch-name].remote [remote-name] # Set it to automatically merge with a specific remote branch when you pull git config branch.[branch-name].merge [remote-master]
You can also manually edit .git/config to set these up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With