3

Here's what I usually do:

$ git add . -Av
$ git commit -m "I want this to be master"

but when I try to push to remote, "everything is up-to-date" and the latest commit isn't master.

$ git branch
* (HEAD detached from f0efe1a)
  added_mongodb_auth
  master
  serviceworkers_branch

How can I make the latest commit the Master?

staminna
  • 468
  • 1
  • 5
  • 26
  • what is the command you're using to push? are your remotes correct? after you commit, you do indeed see a new commit in the log (`git log`)? Are you on the right branch? – jbu Feb 05 '17 at 16:41
  • you probably need to merge your changes to master first. – resting Feb 05 '17 at 16:51
  • What do you see if you run `git branch` before running `git add`? – Shaun Luttin Feb 05 '17 at 18:55
  • @jbu I see the latest commit as expected on top of git log. – staminna Feb 05 '17 at 20:38
  • @resting: can you provide an example? – staminna Feb 05 '17 at 20:39
  • Possible duplicate of [What to do with commit made in a detached head](http://stackoverflow.com/questions/7124486/what-to-do-with-commit-made-in-a-detached-head) – mkrieger1 Feb 05 '17 at 22:25
  • `git push` is not the same thing as `git checkout`, and I have absolutely no idea how you could possibly confuse the two. –  Feb 05 '17 at 22:29

1 Answers1

8

Looking at the output of git branch, it appears you're not currently on any branch (called a "detached HEAD" state).

To be on the safe side, first create a new branch ("save-my-work") containing the commits you've created so far:

$ git branch save-my-work

Now, to include these commits in the master branch:

$ git checkout master
$ git merge save-my-work

Now you should by able to push as usual. If you're sure that master is in the state that you want it, you can delete save-my-work again:

$ git branch -d save-my-work

Tip: Use a graphical repository viewer like gitk to have a better overview of the state of the repository.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • git checkout master results in: HEAD detached from f0efe1a Changes not staged for commit: modified: mongodumps/webapplication/sessions.bson no changes added to commit Jorges-MBP:advgest jorge$ git checkout master error: Your local changes to the following files would be overwritten by checkout: mongodumps/webapplication/sessions.bson Please commit your changes or stash them before you switch branches. Aborting – staminna Feb 06 '17 at 17:58
  • Then you need to *commit your changes* first. – mkrieger1 Feb 06 '17 at 18:00