0

Currently I can push to my remote repository (from local), which updates the remote origin master branch. I can see the changes immediately in github.

If I create a new file from my local repo, add, commit and push to the remote I would like the remote to instantly receive that file after push:

local_repo
-------------
README.md
test1.txt
test2.txt # This is a new file that should appear on the remote after push

However, although Github is updated with the new file instantly, the remote repo isn't updated before I pull the latest changes:

remote_repo (after local push to remote, before remote pull)
------------
README.md
test1.txt

The remote repo shows the most recent changes after pulling from master:

remote_repo (after local push to remote, and after remote pull)
-------------
README.md
test1.txt
test2.txt

How can I have the remote automatically pull and receive the latest changes from its own master branch?

EDIT: My use case and additional details below ****************

I have a game server with many files, which lives on my cloud server (VPS). Traditionally, I would update / add new files by uploading via FTP. I'm looking to replace that workflow with version control.

  • remote_repo is where my game server files live
  • local_repo is where I make updates and modifications to those files, add, commit and push them to "remote origin"
  • I originally thought, by pushing from local_repo to remote, my remote_repo would be updated with the newest changes
  • That is not the case and based on the comments (thanks @TTT), it seems like I need to pull the latest changes into remote_repo, as this repo was never "pushed-into". I was actually "pushing-to" remote origin which is different from my remote_repo

How can I have remote_repo receive the latest changes from remote origin without manually going into the repo and pulling after every push?

bruh
  • 2,205
  • 7
  • 30
  • 42
  • you can write git hook for push actions that will run git fetch – A-_-S Jan 30 '23 at 20:29
  • Is the "remote repo" where the action is running from? If yes, maybe it would help to think of 3 repos here: local repo, GitHub, and a third repo where the action is run from. (I think that would explain what you're witnessing...) – TTT Jan 30 '23 at 21:18
  • Currently i don’t have any actions. With the 3 repo approach, would this be, local_repo, remote_repo (github), and bare_repo? Which repository gets the post-receive action? @TTT – bruh Jan 30 '23 at 23:50
  • I guess I don't know what you mean by "remote_repo". Where are you looking to see what files are shown on "remote_repo"? I was thinking it's just another repo you have somewhere like your local one that you're logging into, and it won't have its file system updated until you pull, the same way your local repo wouldn't update without pulling either. Side Note, the repo you look at in the GitHub UI would be a bare repo. – TTT Jan 31 '23 at 14:00
  • remote_repo is a repo that lives on my cloud server. local_repo is cloned from remote_repo and lives on my local PC. bare_repo.git is a bare repo that I created with the sole purpose of utilizing hooks (i.e. post-receive but I haven't created that hook yet as I'm trying to figure out the correct setup). Reading this aloud, it seems like my concept of "git" may have been skewed. I figured remote_repo (remote origin) was "tied" to Github and should be updated with anything that Github UI shows, when really "remote origin" is just like a conceptual thing of "reference" rather than an actual repo? – bruh Jan 31 '23 at 17:12
  • Based on your comment @TTT , I guess remote_repo is the same as local_repo despite the fact that it lives on a VPS. Thanks for that clarification. I'm updating my original question with an EDIT to show my use case – bruh Jan 31 '23 at 17:15
  • 1
    "...when really 'remote origin' is just like a conceptual thing of 'reference' rather than an actual repo" Kind of, yes. A repo's remote tracking branches, usually named, `origin/*` represent a copy of the commits all of those branches are pointing to on the remote server, at the time you last fetched. You must checkout one of those commits to update the working tree in the repo. A "pull" does the fetch and then a `merge` command which will by default, fast-forward update the currently checked out branch to point to the `origin/*` branch's commit, or merge it in if necessary. – TTT Jan 31 '23 at 18:12
  • 1
    [This question](https://stackoverflow.com/q/3728054/184546) might be a dup, if not closely related. The current top rated answer is the scenario you're in now with 3 repos- it uses a hook to remotely run the `pull` command on your desired server. The second answer suggests moving the bare repo directly to your server so a push would do the update like you expected. There are pros and cons to each. – TTT Jan 31 '23 at 18:18
  • If I understand correct, The action you are looking for is fetch. it updates the remote branch in your local folder. without the actual files in your local repo would be changed. see my answer below – A-_-S Feb 01 '23 at 09:49

1 Answers1

0

you can create a shell script that does:

git push
git fetch

and run it instead of git push

A-_-S
  • 680
  • 5
  • 21