I have some merge conflicts on forge, because we switched to another branch. I now want to have a complete duplicate from my github. Github has the correct code. The code on the server is old. How can I do this? ChatGPT says: git reset --hard origin/3.0-master. But Im a bit scared. I dont want to change anything at github. I only want to replace my code on my server I manage with forge. Or is there a better way?
To replace the code on your server with the code from your GitHub repository without affecting your GitHub repository, you can follow these steps. This approach ensures that your server's code is completely replaced with the code from the desired branch on GitHub.
SSH into Your Server: First, access your server via SSH. You can do this using a terminal or command prompt.
Navigate to Your Project Directory: Change to the directory where your project is located. For example:
cd /path/to/your/project
Fetch the Latest Changes: Ensure you have the latest changes from your GitHub repository.
git fetch origin
Reset to the Desired Branch: Use git reset --hard to reset your local branch to match the remote branch. This will discard any local changes and make your local branch identical to the remote branch.
git reset --hard origin/3.0-master
Clean Untracked Files: If there are any untracked files or directories that you want to remove, you can use:
git clean -fd
Verify the Changes: It's always a good idea to verify that the code is as expected. You can do this by checking the status and logs:
git status
git log -1
By following these steps, you will replace the code on your server with the code from the specified branch on GitHub without affecting your GitHub repository. This method is safe as long as you are sure that you want to discard all local changes on the server.
I found an info at forge, which says "You should not use this function to install an entirely different project onto this site. If you would like to install an entirely different project, you should completely uninstall the existing repository using the "Uninstall Repository" button below."
Maybe it is better to install the branch on a new site. But now I get this problem:
In Connection.php line 813:
Database file at path [/home/forge/stage4.myproject.eu/database/database.sqlite
] does not exist. Ensure this is an absolute path to the database. (Connect
ion: sqlite, SQL: select name from sqlite_master where type = 'table' and n
ame not like 'sqlite_%' order by name)
I also already setup the environment before install the page (because I use mysql), but it does not work. Seems the forge install process overrides this environment.
Hey @pixelairport think about it for a second. What is on your server that is not in the github repo?
Probably only .env file and deployement script. Your data is in the database unless you use sqlite but just to be safe in any scenario back it up. If you use Digital Ocean or AWS backup whole droplet/EC2 to be safe.
Once this is done just create a new site with new repo and once installed switch between them. You can even create brand new server and then switch. There should be really nothing on your server that you can not recover from your github.
Also pay attention to the conflicted files. You might have forgot to gitignore them and that is why you are getting merge conflicts like for instance composer.lock you might have executed composer on both local machine and forge and since it is not gitignored it might be giving you conflict.