question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong branch on the server

See original GitHub issue

When I ran pm2 deploy package.json production setup locally, ssh into the server and go to the source folder, I see it’s not the production branch but a different branch.

In package.json I have clearly defined two different environments with their two different branches. Yet it does not work well:

    "deploy": {
        "production": {
            "user":         "nodejs",
            "host":         "blahblah",
            "port":         "2222",
            "ref":          "origin/master",
            "repo":         "git@github.com:binarykitchen/xxx.io.git",
            "path":         "/var/www/xxx/production",
            "post-deploy":  "npm run-script init-production"
        },
        "staging": {
            "user":         "nodejs",
            "host":         "blahblah",
            "port":         "2222",
            "ref":          "origin/staging",
            "repo":         "git@github.com:binarykitchen/xxx.io.git",
            "path":         "/var/www/xxx/staging",
            "post-deploy":  "npm run-script init-staging"
        }
    },

Any ideas or suggestions why? Or could it be a bug?

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
robschleycommented, Dec 1, 2016

I was having a similar issue, I think I tracked down the issue: https://github.com/Unitech/pm2-deploy/blob/master/deploy#L236

run "cd $path/source && git fetch --all --tags"

From git help:

-t, --tags This is a short-hand for giving “refs/tags/:refs/tags/” refspec from the command line, to ask all tags to be fetched and stored locally. Because this acts as an explicit refspec, the default refspecs (configured with the remote.$name.fetch variable) are overridden and not used.

When you specify --tags, the regular branches are not updated. When attempting to deploy, it was not updating the source code to the latest in my origin/develop branch despite having specified that as the ref. I discovered this by running git fetch --all on the server and noticed that it finally dowloaded the updates. I added the line below to the deploy config and ran it by hand once on the server to pull down the latest config changes. Now it will pull down all updates before it does the git reset --hard which does update based on the most recently fetched commits as @rchan-pp mentioned:

'pre-deploy': 'git fetch --all',

I suspect this is a bug as it prevents you from checking out a commit/branch that is ahead of where the server has previously fetched. I hope that helps.

0reactions
rleiracommented, Feb 13, 2019

This looks like it could be related to this issue: https://github.com/Unitech/pm2/issues/3803

Read more comments on GitHub >

github_iconTop Results From Across the Web

What to do when you commit to the wrong Git branch pt. 2
The golden rule is to: Never rewrite the history of a branch that you have already pushed to a Git server and shared...
Read more >
Git pulled from wrong branch - Stack Overflow
I have two branches on the server A branch called R2 and a branch called DEV I inadvertently logged into the wrong server,...
Read more >
Git tip: how to fix an accidental commit on the wrong branch
Oh no, you just accidentally commited to master , when you were supposed to work on a feature branch! How to fix it?...
Read more >
Fixing things when you push changes to the wrong branch on ...
You've git pushed commits to the wrong branch on github. How do you use git to revert them safely and get your project...
Read more >
Git tag set on wrong branch - Visual Studio Feedback
Please also check in your local give repository, run the 'gitk --all' command. It shows clearly which tag point to which commits and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found