Noble-Surfer
Noble-Surfer

Reputation: 3172

Git- local master branch appears to be broken

I am working on a Python/ Django project, using Git to manage my version control.

On the live server, the website currently works as expected, however, I have made a couple of changes to the layout/ presentation of one of the views on my local copy.

To do this, when my local master branch was up to date with the live version, I created a new branch from master called pipelineProject, and started working on that branch. While making changes on pipelineProject, I 'broke' the website during the course of making changes, and had to revert that branch to the state of master a couple of times.

I have now got my pipelineProject branch to a state where the changes I wanted to make work correctly- I have run git add -A and git commit -m 'message' to ensure that my working pipelineProject branch is backed up.

However, after backing up pipelineProject, I then checked out master, as I obviously wanted to merge my changes with master, and before merging my changes, I tried loading my website in the browser while on master branch- but for some reason this is now broken... although the website loads, all of the styling has disappeared- and the page just displays a list of the HTML elements used in the page (hyperlinks, titles & a few variable names from the code)

The live version of the website is still in the same working state as it was before I started working on these changes, so I tried switching to my local master branch, and running git pull origin master to update my local master copy with the copy that is currently running on the server.

When I did this, git displayed a message saying:

Already up-to-date

I don't understand why this is... if my local master is up-to-date, then why am I able to view the website correctly on the live server, but when I view it on my local server, it doesn't display correctly...?

When I view the website locally on my pipelineProject branch it all works correctly (and the changes that I have made are displayed as expected), but I don't want to merge my pipelineProject branch into my local master branch in case I lose the changes that I have successfully made.

Why is it that my local master is broken, when the live master works, even though the two are identical? How can I fix this before pushing my changes to the live server?

Edit

Just a thought: since my pipelineProject branch seems be working correctly, could I replace my local master branch with this one, and then push that to the server?

Is there a reason why my local master would be broken even though it is up-to-date with the live one when the live one works?

Upvotes: 0

Views: 931

Answers (2)

Marina Liu
Marina Liu

Reputation: 38096

For your questions:

  1. Yes, you can replace master branch with pipelineProject branch. First you should make pipelineProject branch to track origin/master, use git checkout pipelineProject and git branch pipelineProject -u origin/master, then delete local master branch git branch –D master, finally rename pipelineProject to master git branch -m pipelineProject master
  2. Yes, there has a reason for it. It’s caused by the local master branch is ahead of origin/master branch for remote (you can use git status to check), and you can view commits which are ahead of the origin/master, use git log origin/master..master. So for your situation you need to drop the “broken” commit, you can use git reset --hard <commit id which you want go back>(if you do't willing to delete master branch)

Upvotes: 1

Sajib Khan
Sajib Khan

Reputation: 24136

  1. Make sure your local & remote master are in same commit-sha
    $ git checkout pipelineProject # go to your pipelineProject branch
    $ git branch -D master # delete the local master branch

    Then go to online and copy the master's last commit sha
    $ git checkout paste-commit-sha-here # go to the remote master's last commit
    $ git checkout -b master # create & checkout local master branch

  2. Replace local master with pipelineProject and push to server

    $ git checkout pipelineProject # go to your pipelineProject branch
    $ git branch -D master # delete the local master branch
    $ git checkout -b master # create & checkout new local master
    $ git push -f origin master # push to server forcely

Upvotes: 0

Related Questions