61

I am making changes to some file in my local git repository and then want to send the changes to the remote git repository from which the local was cloned via ssh.

After run "git commit -a" on my local side, to send the changes to the remote, I run

$ git push
Everything up-to-date

However I checked the remote files and they are not changed! Any idea?

Thanks and regards!

0

18 Answers 18

34

I found that the issue was that I had not added the files to the update as well as a message. I fixed this by using the following commands:

git add .

and then

git commit -m "updates done by..."

and then

git push origin <repo_name>

Hope this helps someone ;)

2
  • 1
    Dang it! Yeah, the obvious things... This helped me.
    – Richard
    Commented Feb 1, 2021 at 17:44
  • This was the answer I needed as I'd added the file, but forgotten to "commit" those added files so they could be pushed. However git add . should be used with caution as it will add every changed file, even if you didn't want all of them. Commented May 27, 2022 at 10:45
28

Have you tried the following?

 $ git push origin master:master

Use git remote to find out the name(s) of your remote(s). The default remote is origin, which is automatically created when cloning a repository.

5
  • The first master for local branch, the second for remote branch. Commented Oct 24, 2017 at 21:41
  • @knittl I got this error. fatal: 'origin' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
    – vishal
    Commented Nov 30, 2021 at 17:56
  • @vishal I don't understand your latest comment and it doesn't answer my question. What does git remote or git remote -v show? Does it contain a line for origin? If not, which remotes do you have configured (i.e. are shown by the command)?
    – knittl
    Commented Dec 1, 2021 at 6:08
  • @knittl, sorry for the late reply. This is output - heroku git.heroku.com/video-chat-app-random.git (fetch). heroku git.heroku.com/video-chat-app-random.git (push)
    – vishal
    Commented Dec 3, 2021 at 5:31
  • @vishal you do not have an origin remote configured. Yours is called heroku. Therefore, your command needs to become git push heroku master:master
    – knittl
    Commented Dec 3, 2021 at 5:53
24

You probably pushed into a non-bare repository, i.e. a repository that has a working copy attached to it. You shouldn’t have ignored the warning git push gives you if it notices that this is the case.

Anyway, log in to the remote machine, change to the repository and do

git checkout <whatever branch you’re on>

There you go. Next time only push into bare repositories. :)

4
  • 5
    I managed to solve this problem as what you said but I am still confused and not understand what I was doing. Does non-bare means that I can edit files in the repository directly and bare means that the files in the repository does not allow to be edited? What kind of warning git push gives, which I didn't notice? Thanks!
    – Tim
    Commented Aug 19, 2009 at 13:55
  • 3
    A “bare” repository is a repository that does not have a working copy, i.e. you can not edit any files in it. The repository path directly contains everything that is normally in the .git folder of a non-bare repository, and in fact a bare repository is only this folder. When pushing to a non-bare repository you do not change the files that are currently checked out. You need to update the working code separately, e.g. with git checkout or git reset.
    – Bombe
    Commented Aug 19, 2009 at 14:22
  • So you have to switch to a branch that isn't being worked on in order to push to it?
    – user9903
    Commented Apr 25, 2011 at 17:15
  • Just don’t push into a repository that has a working tree attached. The warning is there for a reason! If you do not understand the ramifications of pushing into a non-bare repository, then don’t do it. Don’t look for workarounds but use a sensible structure instead: push to a bare repository somewhere else and then pull from your destination.
    – Bombe
    Commented Apr 29, 2011 at 7:08
10

I had the same issue and it was because I had checked out to a point in the history (in this case a tag), rather than the end (head) of any branch or master. I would make the change and commit which would succeed and I would see the changes in my local history. When I ran git push, git stated everything was fine, but the change had not actually been submitted to the server (which can be seen by checking the logs, or by re-cloning the repo and checking it's logs). The best symptom of this mistake is seeing the message "Head detatched from ____"

The Solution

What one actually needs to do (if you have done what I've done) is create a new line of development by creating a branch and switching to that branch before making the changes.

git branch [a new branch name]
git checkout [a new branch name]  

Then after committing the changes, if you want the changes to be pushed to the server you need to push the branch itself to the server.

git push -u origin [local branch name]

Now if you clone the repository, you should see your changes in the logs. However, next time you clone the repository, to be able to go to that point you just changed, you will need to checkout that branch, as you will default to being on the main line which is "further" down the development line from where you branched off.

git checkout [branch name]  
1
  • 1
    This is exactly the mistake I made. Once I created the new branch, I switched to it, and then used the push command, and then all the commits I made were then added to the remote repository.
    – focus1691
    Commented Jun 24, 2017 at 23:38
5
git commit --amend

Will change the commit ID and make the remote repository "think" new changes has been made.

1
  • This worked for me when I pushed some changes to github while they had an incident opened for "degraded git operations (pull push). My changes showed up to date locally but remote branch did not reflect them. Thanks! Commented Jan 29, 2022 at 21:37
2

None of these solutions worked for me, and the commits would appear on my live website only after running GIT_WORK_TREE=/path/to/website git checkout -f. If this is your case you have to add a "hook" to your git configuration.

  1. Go to your the hooks folder inside your git folder:

    cd ~/path/.git

    cd hooks

    nano post-receive

  2. Write this line in the post-receive file:

    GIT_WORK_TREE=/path/to/your/website/or/project/ git checkout -f

  3. Lastly, you have to modify the permissions of the post-receive file:

    chmod a+x post-receive

This will execute that command every time you push, updating your commits on your remote project.

1
  • Thank you and ofcourse that GIT_WORK_TREE=/path/to/your/website/or/project/ git checkout -f should be written in website remote server. Commented Aug 5, 2023 at 7:23
2

Well, this is what worked for me

git stash

git pull

git add .

git commit -m "commit message"

git push
1

type "git log" in your remote repository to see if it contains the newest commit. If not, you should check the configuration of you local repository to see the remote settings.

To see the changes in different type of your remote repository:

A. If your remote repository is bare, you can find the files in the remote repository branches/ config description HEAD hooks/ info/ objects/ refs/

after new commit is pushed, files in objects/ directory would changed.

B. If your remote repository is non-bare, type "git checkout master" And "git status" in your remote repository to see the file status. See if some file has been modified or deleted.

1

I had precisely the same problem as a new git/github user. You have to write this into the command line:

git push -u origin master

That should fix your issue.

1

I suggest you look into using gitosis for hosting those git bare repositories. It's really easy to use after the initial setup.

0

One other issue could be that while you might have used

git add your-dirs

You have to remember to commit the files within directories

git commit -m'Add your message' your-dir/*

Then add a git push in order to push it to your remote

0

I just experienced a similarly frustrating occurrence of not seeing my change replicated on github. As a new git user, just getting used to the using the system, I created a folder on my computer, added it, committed it, pushed it - no change. I considered the possibility that I cannot push an empty directory, so I created an empty file in the directory and then repeated the above steps. All better, the change was instantly mirrored in my github repo.

0

One solution is remove the remote and re-insert it, just to reset your local tree and presettings. This issue happens with me when I move folders manually.

To remove yours remotes:

$ git stash

Then:

$ git remote rm <REMOTE NAME> 

i.e. git remote rm origin.

Add again your remote:

$ git remote add origin <URL>
0

I was facing the same issue and I tried several things none of which worked.

In the end, I added one dummy commit and again pushed the changes and now I can see both (previous one and dummy one) on GitHub remote repository.

0

Sometimes it just happens due to loading issues. Try opening the link from the branch menu directly in another new tab. This worked for me.

0

Since i had a similar issue on CentoS 7 with NetworkManager. Pinging the git server gave a response, connecting with netcat (nc) also gave a response, even trying to connect with ssh worked. But the git command just kept on hanging.

In the end it turns out that instead of using NetworkManager and its DNS settings to resolve the git server an entry in /etc/hosts pointed to a wrong ip address which was not reachable.

0

assuming you are using VScode: go to the file that ain't reflecting changes press CTRL+S if it shows that the file is different from the one saved in the repo then click compare save the modified file using the icon over the tab and then type:

git add . ; git commit -m "changes" ; git push origin master

You can add -f but avoid it if multiple people are using the project to avoid conflicts:

git add . ; git commit -m "changes" ; git push origin master -f

A similar issue happened to me and got me confused for a while.

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Mar 25, 2023 at 21:26
0

I came here searching for solutions and tried all the suggestions made here. None worked for me. Well of course out of frustration. I did the following which worked for me me.

  1. i created another local branch
  2. added all files with git add -A
  3. then i did i merge my origin/main with my new branch
  4. then i push!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.