Karun
Karun

Reputation: 577

Git, working between local branch and remote

I cloned a repository and got a master branch. From the master I created a local branch "abc". Now the remote may have progressed. The branches look like this:

>git branch -a
* abc
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  1. How do I see the diff between local branch abc and remote.
  2. How do I get the remote changes merged to my local banch "abc".
  3. Can I push my local changes from "abc" directly to remote, or will I have to go via my local master.

Upvotes: 2

Views: 319

Answers (1)

poke
poke

Reputation: 387507

  1. git diff origin/master..abc for a diff between origin’s master and your local abc. Note that this reflects the state of your local repository, so if you want to make sure that all new changes from the remote are there, git fetch first.
  2. In general git pull or more explicit git pull origin master. If you want to pull to abc you can also git fetch first to get all remote changes into your local repository (as remote branches) and then manually merge using git merge origin/master.
  3. git push origin <targetbranch>. So if you want to create a branch abc on the remote, use git push origin abc. If you want to push to origin’s master, use git push origin master. This will fail if the remote cannot fast forward though, in that case you need to push explicitely with --force.

Upvotes: 3

Related Questions