I ‘m relatively new to git and and having some problems early on. I’ve made several commits, but when I try to push them I get a response that says everything is up-to-date. I feel like my problem is the same on listed in this question, but it recommends the following:
$ git log -1
# note the SHA-1 of latest commit
$ git checkout master
# reset your branch head to your previously detached commit
$ git reset --hard <commit-id>
What exactly will “checking out the master” do? I just don’t want to lose the changes I’ve made…
screenshot of gitk:

Checking out a branch moves the local
HEADpointer so that it’s pointing at the same commit that the branch references. For example:When on branch
mybranch(theCs are commits):After running
git checkout master:This also moves files in your working directory as required so that it is a perfect snapshot of what the project looked like at that commit. It does not delete or alter commits, so you won’t lose work in one branch by checking out another.
What has happened in the case of a “detached head” as described in that other question is that
C3is not associated with a branch. In order to fix this, you need to update the commit that themasterbranch points to so that it includes the new stuff (C3). Checking outmastertells git that you are now working with the master branch, then doing a hardresetwith the SHA1 of the commit that you want to be at the tip of yourmasterbranch updates the branch references to what you want.Edit:
In this case, a detached head was not the issue. Just remember that committing and pushing are two different things in git. Committing does not communicate with a central repository like it does in Subversion. After you make changes to your working directory, you run
git add filenameonce for each file you’ve changed, wherefilenameis the name of the file. Once all the files have been added to the index, you commit them withgit commit.A shorthand for this is to use
git commit -awhich will automatically add modified files to the index before committing. This allows you to skip thegit addsteps. Note thatgit commit -awill only add modified files. If you’re introducing a new file that has never been committed, you must manually add it withgit add.Once your commit has been made, you can run
git pushto send that commit to your remote repository and update the remote branches. This only does the remote communication stuff. Unlike Subversion, the commit itself is handled locally, without any interaction with the server.