-1

Apologies in advance. I'm sure this is a very simple question with a very simple answer but I'm a beginner at Git and I'm a bit lost. I have a master branch. I made some changes yesterday and performed git add ., git commit, made a new branch by doing git branch part-one, then I pushed the commits to that new branch by doing git push origin part-one. I see that my commits got pushed into that branch on github. Now, I did some more work on the same files. I added and staged the changes just as before. Now when I go to push the commits by doing git push origin part-one it says Everything up-to-date. I don't see the most recent commits in my history on github.

Why is it not pushing the most recent commit to my part-one branch?

Possible cause: If I wanted to push these commits to my branch. Was I supposed to be do git checkout part-one, then do git add and git commit? I did those commands while I was on the master.

  • What you really need is a good tutorial on GIt. Unfortunately, there are a lot of *bad* ones, and not that many good ones. Adding GitHub into the mix makes things more complicated, because some of the ways that GitHub shows you stuff is ... misleading, I think is a good word: GitHub tries to simplify a complicated world. That's fine as far as it goes, but sometimes—too often—they hide things that actually *matter*. – torek May 29 '20 at 08:02
  • The [Pro Git book](https://git-scm.com/book/en/v2) is the only book I know of that is both comprehensive and free. – torek May 29 '20 at 08:05

3 Answers3

0

You stopped after staging, you haven't committed, nothing to push (that's following your descruption). You said added and then staged.... that's the same thing. You meant added and committed?

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • Sorry. I'm not sure I follow. I did do `git add` and `git commit` for my most recent changes. Isn't that committing the changes? – NewAtLearningThis May 29 '20 at 05:30
  • Hmm.... if you committed and pushed, they should be there. Make sure what branch you are working on and the sequence of commits with `git log --all --decoration` – eftshift0 May 29 '20 at 05:33
  • Yes, I see it is there. It has a commit hash and says (HEAD -> master). I'm not sure if that means anything or that is what's wrong. Sorry, I think I made it a bit unclear. I added and staged the commits. It's just not allowing me to push those staged commits to my branch – NewAtLearningThis May 29 '20 at 05:35
  • If I wanted to push these commits to my branch. Was I supposed to be do `git checkout part-one`, then do `git add` and `git commit`? I did those commands while I was on the master. – NewAtLearningThis May 29 '20 at 05:56
  • You could place part-one where master is: `git checkout part-one; hit merge master`. Given that part-one was created but hasn't moved (right?), it should fast-forward to where master is.... then you could push it. – eftshift0 May 29 '20 at 12:34
0

You where on a branch, say master for simplicity. The name doesn't matter.

You added all files to the tracked files list (git add .), then created a commit on branch master (git commit).

You tried pushing this commit to a remote branch, on a different branch that is, not on remote master.

You are not really allowed to do so, for a number of reasons. Say the commit you created was child of commit X. Commit X exists on both local and remote master branch. Commit X does not exists on remote part-one, so there is no easy way to explain how to apply the edits starting from last commit of part-one, which is commit Y, say.

In the end, you want to move commits to a new branch, or perform a merge of master onto part-one, or git commit --amend to destroy last commit you made on master, then git switch part-one and git commit -a there.

Daemon Painter
  • 3,208
  • 3
  • 29
  • 44
0

In case anyone comes across this in the future: here's the solution that worked for me.

The problem was I had commits on my master that I actually wanted on my branch. What I did was this. I merged my branch with my master meaning that the branch will get all the commits from master, and the master will get all the commits from branch. From here, depending on what you need; you can use git reset --keep HEAD~X where X is how many commits you want to delete. You can then push the commits to your Github.

For reference: this was it Move the most recent commit(s) to a new branch with Git