4

So, I've been trying to get my staging branch workin' all day but I'm missing something.

This is the chain of events:

git branch 
develop
*master
staging

make some changes

git checkout staging
M   app/views/comments/index.html.erb
M   app/views/devise/registrations/new.html.erb
M   app/views/devise/sessions/new.html.erb
M   app/views/layouts/application.html.erb
M   app/views/songs/contact.html.erb
M   app/views/songs/faq.html.erb
M   app/views/songs/index.html.erb
M   app/views/songs/new.html.erb
M   app/views/songs/new_songs.html.erb
Switched to branch 'staging'

git gui (git commit and then git push staging)
git checkout master
git push staging master (deployment)

Everything up-to-date

Everything isn't up to date, I just made 10 changes that I'd like to see on my staging server.

How can I get this workin' ?

Ajedi32
  • 45,670
  • 22
  • 127
  • 172
Apane101
  • 1,121
  • 1
  • 14
  • 37
  • http://chat.stackoverflow.com/rooms/35621/http-stackoverflow-com-questions-18280962-everythings-up-to-date-everything-isn – rmagnum2002 Aug 16 '13 at 19:53
  • why does your `git checkout` output look like `git status`? can you do your `git gui` things in command line to give us an exact idea what you are doing? For the push, are you sure you have a remote called `staging` and you want to push your local master branch to it? – michas Aug 16 '13 at 20:16
  • I'm confused. Is `staging` a remote, or a branch? You seem to be using it like both... – Ajedi32 Aug 16 '13 at 20:22
  • @michas That's what `git checkout` looks like when you have tracked changes in your working directory. – Ajedi32 Aug 16 '13 at 20:36
  • @Ajedi32 Shouldn't git refuse to change branch in case of uncommitted changes? How do I get in such a situation? – michas Aug 17 '13 at 21:16
  • @michas Only if the changes would be overwritten by the checkout. Otherwise, the checkout succeeds and you get that message. – Ajedi32 Aug 17 '13 at 22:39

2 Answers2

1

There is a key step missing from your workflow: Adding changes before committing them.

Before using git commit, run git add -A to add all files in the working directory to your git repo. Alternatively, you can use git add <path-to-file> to add a specific file, or use git commit -a to add all modifications to your git repo. Note, however that git commit -a won't add new files, it will just add changes you've made to preexisting files.

If you ever want to see where you're at, type git status. Red files are changed, unstaged("staging" a change is equivalent to "adding" it), while green files have been added. If git status says "working directory clean", then you haven't made any changes since your last commit.

Nick
  • 9,493
  • 8
  • 43
  • 66
Benno
  • 99
  • 1
  • 3
0

Make sure you use git status (or git status --short) frequently. Whenever it shows changes you have to decide if you want to keep them or not. Then you commit them or discard them. - Afterwards git status is happy again. Setting up a meaningful prompt is usually very helpful.

Do not change branch without a clean git status. (It only worked because both branches were pretty much equal.)

The main problem seems to be your push. git push requires you to specify a remote (usually called origin). If you really want to push the content of your local staging branch to the remote master you can do it by git push origin staging:master, but this will pretty sure make things even more complicated.

You have two options: either go with only one master branch or with an additional staging branch.

  1. With only master you pull your changes from the remote master, which created (or updates) your local master. Then you do your commits on your local master, and when finished push your local master back to the remote master, which should deploy it.
  2. With a separate staging branch, you can do your changes on the staging branch push your local staging branch to the remote staging branch, where you might deploy it is some kind of staging area. If you are happy with the results you merge the staging branch to the master branch and push the resulting master now containing all staging changes.
Community
  • 1
  • 1
michas
  • 25,361
  • 15
  • 76
  • 121