1

The remote repo has master and staging branches, and I am only supposed to work in staging. The first thing I did was clone the repo down to my local computer. Then I used git checkout -b form origin/staging to create and checkout a new local branch and have that track the origin/staging remote.

Now I have several commits and am ready to push that to the staging. How do I do that? Can I simply type git push? If I did that, will it just push my commits into the staging branch on the remote or will it create a new branch called forms into the repo which is not what I want.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • You should probably first `git pull --rebase` to get the newest changes to `origin/staging` and `push` afterwards. – Micha Wiedenmann May 17 '13 at 17:00
  • @Micha - right already used git fetch prior...but my concern is still if the commit will go into proper staging branch and not create a new branch...Also I don't want to inadvertently push to the master... –  May 17 '13 at 17:02
  • They will go into the correct branch. But you can always just create two repositories on your machine and try out the commands you are unsure about. – Micha Wiedenmann May 17 '13 at 17:03

1 Answers1

1

You can use:

git push repo_name from:to

So for your case:

git push origin form:staging

You could need to update your code before:

# will update merging
git pull

Or:

# will update rebasing
git pull --rebase

For a difference between rebase and merge check this.

You could also pass your changes in form to staging local branches:

# to change local branch
git checkout staging

# to get changes from form branch in staging branch
git merge form

# to push corresponding branch
git push

This way you won't have to give a refspec from:to

sites
  • 21,417
  • 17
  • 87
  • 146
  • ok I guess "origin" is the word that scares me. In my local I have master and a branch called "form" as I am working with html forms. I was just afraid "origin" would mean master and I would be pushing master to the staging when I wanted "form" to be pushed... –  May 17 '13 at 17:15
  • Just to be clear, if I type git status, it says I have 6 commits ahead of the origin/staging. And if I type git push...nothing happens. It just says "already up to date"...so that doesn't work. So I am assuming I have to use what you provided? –  May 17 '13 at 17:17
  • Origin is the name of your remote repo. – cortex May 17 '13 at 17:17
  • yes, you have to use what I wrote, but is more organised to incorporate your commits to staging branch, let me update answer – sites May 17 '13 at 17:19
  • Thank you for this! last question is there a difference between using pull --rebase versus fetch first and then merge? –  May 17 '13 at 17:28
  • yes, `pull --rebase` does `fetch` and then `rebase`, while the other thing you are mentioning is `fetch` and then `merge`, which is equivalent to `git pull` without modifiers. – sites May 17 '13 at 19:00