2

I have a local branch in my sandbox repository called local-branch which tracks a remote branch called remote-branch. I created the local branch thus:

$ git checkout -b local-branch remotes/origin/remote-branch 

I created a branch from the local-branch called dev-branch:

$ git checkout -b dev-branch local-branch 

I then committed some changes to dev-branch and now want to push it upstream to a branch off remote-branch. There it gets reviewed, approved and then merged into remote-branch. Following that, I need to git pull on my local-branch to sync it with remote-branch.

I am trying the following but this does not seem to work.

$ git push remotes/origin/remote-branch local-branch 

I see the following error:

fatal: 'remotes/origin/remote-branch' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 

But I can see the repository when I run:

$ git branch -a 
1
  • Looks like: $ git push origin local-branch works. Commented Nov 20, 2015 at 13:21

1 Answer 1

4

To push local-branch from your repository into remote-branch on remote origin, use

git push origin local-branch:remote-branch 

Based on the way you created local-branch in your question, git should have configured it to track origin/remote-branch. In that case, a simple git pull while local-branch is checked out will suffice to sync.

Your workflow is complicated. I suggest looking for ways to simplify that involve fewer names for each given branch.

Sign up to request clarification or add additional context in comments.

1 Comment

The whole local-branch is redundant, since it doesn't seem to be used as a working branch. Just creating dev-branch from where ever remote-branch was pointing is enough. Then just git push origin dev-branch when done with the working branch. I'm guessing there's some misunderstanding about what branches mean in Git: branches do not refer to other branches, only commits, which in turn link to their parent commits. There's no link from parent to child. That would require a rewrite of the latest commit on a new commit. Which is the reason why "dangling commits" are bad.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.