This is a very beginner question on Git. I am following along the book here and website here with respect to branching and merging.
I have a readme file on github that I pull onto my local machine where i create a branch, update the readme file and attempt to merge it back to the main/origin. I cant seem to get the last step right and i would appreciate any pointers.
$ git add README.md
# Creates a commit
$ git commit -m 'first commit of the day'
# Pushes the commit to github - no issues
$ git push
# Create and checkout a branch called issue-1
$ git branch issue-1
$ git checkout issue-1
Its at this point i update the readme file with an additional line of text, something like "hello world"
# Assume I am still on the branch, I commit my changes
$ git commit --all -m "Completed issue; issue 1 closed"
# Now i check out the main portion of my project that i want to merge my
# changes into and I merge this into my main project origin.
$ git checkout origin
# Note: switching to 'origin'.
# You are in 'detached HEAD' state. You can look around, make experimental
# changes and commit them, and you can discard any commits you make in
# this state without impacting any branch.....
$ git merge issue-1
# Updating 0ad9cb3..8f0455d
# Fast-forward
# README.md | 1
# 1 file changed, 1 insertion( )
This doesn't actually merge my changes into the main project. If i attempt to push it back to github:
$ git push
# fatal: You are not currently on a branch.
# To push the history leading to the current (detached HEAD)
# state now, use
git push origin HEAD:<name-of-remote-branch>
CodePudding user response:
You want to go back from branch issue-1
to master
or main
.
You should do git checkout master
or git checkout main
instead of git checkout origin
.
origin
is the name of the remote (which is GitHub in your case). Not the name of a branch.