1

I have a GitHub repo, and a local repo on my computer. Let's call them origin/foo and local/foo. I know how to sync work between my local machine and the online GitHub repo, for Mater branch only.

I then go ahead and use the GitHub online client to make a branch origin/foo:next. I make a similar branch on my machine, called local/foo:next. Is there a way I can push the local changes of local/foo:next to the online repo of origin/foo:next, without changing the master branch of either repo?

Avi Caspe
  • 537
  • 4
  • 12
  • Cant you just git fetch and then git checkout the new branch. (See http://stackoverflow.com/questions/1783405/how-to-check-out-a-remote-git-branch ) – visibleman May 16 '17 at 06:22
  • 1
    Just to be clear, you actually have a colon in the branch name? – 1615903 May 16 '17 at 06:50
  • Yeah. It's how I do things. – Avi Caspe May 16 '17 at 06:55
  • 1
    It's not a good way to do things because git uses the colon in some commands to separate local branch name from remote branch name, in other words, the colon has a special meaning with git. See [Why Git use the colon (:) to delete remote branch](http://stackoverflow.com/questions/7303687/why-git-use-the-colon-branch-to-delete-remote-branch) for one example. – Lasse V. Karlsen May 16 '17 at 07:55
  • 1
    Interesting. How do you actually create the branch locally? All i get is `fatal: 'foo:bar' is not a valid branch name.` – 1615903 May 16 '17 at 08:12
  • 2
    @1615903: indeed, `:` is forbidden in any reference name anywhere (along with control characters, spaces, tildes, and carets; see https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html) – torek May 16 '17 at 08:14

2 Answers2

0

You can push the local foo:next branch to the remote like this

git checkout foo:next
git push origin foo:next

This won't affect the master branch.

Aurélien Gasser
  • 3,043
  • 1
  • 20
  • 25
0

As you are already on a branch you can simply push your changes to the online repo origin/foo using :

> git push origin foo:next

Here's a guideline you can follow to use git more efficiently :

  1. Before working on a new feature update your remote master

    git pull --rebase origin/foo master

  2. Create a new branch from your local master

    git checkout -b feature/my-feature

  3. Make your code changes. Commit the changes and push to remote branch

    git push origin foo:next

  4. Raise a PR and merge to the required repository.

Abc_omega
  • 11
  • 3