How do I place my entire WordPress installation under git control? [closed] - wordpress

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How do I place my entire WordPress installation under git control? I am using Github on a Mac computer and I need to push all my work to a remote repository.

So the process is straight forward, but don't forget to include a dump of the database to your repository.
say you have the WordPress setup on /Users/yourHome/theSite, then:
create or copy a backup of the site's DB to /Users/yourHome/theSite/dbdump
go to the site folder cd /Users/yourHome/theSite
Stage everything git add .
commit them git commit -m 'Your commit message
set the repository's remote to where you have to push git remote set-url origin https://example.com/remote/sample.git
and finally push git push -u origin master
please note I'm assuming you already have git repo on the site location. otherwise you need to initiate on in the location before the step 2. lest say as step 1.5 :) git init
so after having the db back up ready, you have to:
cp -rf the/db/backup/* /Users/yourHome/theSite/dbdump/
cd /Users/yourHome/theSite/dbdump
git init
git add .
git commit -m 'Your commit message'
git remote set-url origin https://example.com/remote/sample.git
git push -u origin master

Related

adding version control Git to my already deployed wp website

I have a wordpress website on hostinger and im trying use version control Git on it without downloading the files locally but i have no idea what to do or where to start ! my goal would be pushing to github as if im working locally (but im not the files are on the server and i dont want to download them ) please Help.
You need to initiate a git repo for the files on a server and add a GitHub repo as the remote for this. Then you can push files from your Hostinger server to GitHub. To do this, you will ideally need SSH access to your hosting. This seems possible with Hostinger depending on your hosting plan. See how to login to hostinger account via SSH.
Once you've logged into your hosting account via SSH:
Change into your website's folder using cd /path/to/folder
Start a new git repo in this folder using git init
Add all your existing files using git add .
Commit the files you've added using git commit -m "Commit message"
Create a new repo on GitHub (if you haven't already)
Add the empty GitHub repo as the remote for the files on your server using git remote add origin git#github.com:username/repo-name.git
You should now be able to push files to GitHub using git push origin main or git push origin master
Good day.
Unfortunately you can not push at once from hostinger to Github.
I have 7 steps for you to push all code to the GIT server:
1)Install github locally
Download github
2)Copy the files of your website to local directory
3)Open cmd.exe on windows follow to your catalog with Website files and run next command to initialize new git repository locally
git init
4)Add files to your locall repo
git add .
5)Add commit
git commit -m "First commit of website"
6)Create remote repo link for your website on github.com and copy link to the next command(replace CAPS)
git remote add origin https://github.com/USERNAME/REPO_NAME.git
7)Push all files to Github
git push origin master

Git - Can't Push - "! [remote rejected] master -> master (Working directory has unstaged changes)"

I am trying to set up a "simple" git workflow for a Wordpress installation that has a local version, a staging version and a production version. All I want to do is make changes locally and push from local to staging and from local to production. At first I thought this would be a simple task. I have been able to initialize the repository, add the two remotes "staging" and "production", initialize git on the remotes and push changes from my local version to the staging and production servers normally using the commands:
git add .
git commit -m "some changes"
git push staging master
git push production master
However, at some point during my work something changed, and while I am still able to push to Staging, now I am unable to push to the Production server without getting the error:
! [remote rejected] master -> master (Working directory has unstaged changes)
When I do "git status" it says:
On branch master
nothing to commit, working tree clean
After reading the answers to several SIMILAR BUT DIFFERENT questions on Stack Overflow I have tried the following:
git pull staging master
git pull staging master --rebase
git pull production master
git pull production master --rebase
I also tried executing this command on the remote servers
git config --local receive.denyCurrentBranch updateInstead
I have already completely re-created the servers and repositories a few times just to re-install git entirely from scratch, but this problem keeps happening after a while and at this point Git is actually HURTING my workflow instead of helping it. If anyone has any insight into what my mistake is, it would be much appreciated!
I had similar problems, pushing to a non-bare remote repo where I wanted the working copy files to be checked out immediately.
My remote was configured with receive.denyCurrentBranch updateInstead, but it still refused to accept pushes at unpredictable times.
Git 2.4 added a push-to-checkout hook, which can override such push failures.
I wrote a short script based on the example in the githooks documentation.
#!/bin/sh
set -ex
git read-tree --reset -u HEAD "$1"
I installed this script in .git/hooks/push-to-checkout in my remote repo.
Note that this script overwrites the working copy in the remote — it does not attempt to merge any changes to those files.
That's because I want the working copy to simply reflect the files in the repo.
Making a git bare repo is the best practice to push to.
You could push to a non-bare one... but only if you are not modifying files on the destination side while you are pushing file from the source side. See push-to-deploy.
But the best practice remains to add a post-receive hook (as in my other answer) in order to checkout in an actual folder all the files you have received.

'fatal: remote part of refspec is not a valid name in ..' error when setting up Git [duplicate]

This question already has answers here:
git push origin gives remote part of refspec is not a valid name
(7 answers)
Closed 8 years ago.
I'm trying to setup git with WPengine following the instructions here: (http://wpengine.com/git/#production) - but when I get down to the deploy step, I get the following error:
% git remote -v
production git#git.wpengine.com:production/workshop-wp.git (fetch)
production git#git.wpengine.com:production/workshop-wp.git (push)
% git push production master ...
fatal: remote part of refspec is not a valid name in ...
Don't put ... in the push command. The correct syntax is
git push production master
I know that the instructions in the tutorial that you linked to say to do this:
git push production master ...
but that's just blatantly incorrect.
I got it to work. I was trying to deploy my GitHub repo name:
$ git remote add production git#git.wpengine.com:production/my_wordpress_app.git
Instead of deploying my wpengine username
$ git remote add production git#git.wpengine.com:production/robertwilliams.git

Update Wordpress when using Github Wordpress skeleton

This is mainly a clarification about dealing with public Repos for git beginners.
I have a local git repo with a clone of Wordpress skeleton (https://github.com/markjaquith/WordPress-Skeleton). This includes Wordpress as a submodule (https://github.com/WordPress/WordPress).
If I update Wordpress from the dashboard it will require me to update my git repo.
There is a note about making a pull request if the repo falls behind but I am working on my localhost so can't do that.
If I had a hosted repo, should I send a pull request to the WP skeleton or WP repo?
I have a fresh install at the moment but if I were to customise it I probably wont want to (or Shouldn't) push so what would I do in this case?
Note: This is using the Wordpress repo as an example but I am curious about the best/general practice.
I'm having some similar questions, mainly about what the best practice is when updating Wordpress. Should I use the Dashboard once on remote, or should I continue to update the Wordpress Submodule in WP-Skeleton.
I can tell you this, you can update Wordpress via the Submodule in WP-Skeleton by using the "Git Checkout" command on the submodule and choosing the latest release number (4.1 as of this writing). Its extremely simple in SourceTree if you're new to Git and need an interface to help.
This is a little late but I asked the author of the repo and he answered me in his QA repo on Github.
This is the answer Mark Jaquith gave there which worked:
For your personal sites, which have likely wildly diverged, the update
process is as follows:
cd wp
git fetch
git fetch --tags
git checkout 3.9.1
cd ../
git add wp
git commit -m 'Update to WordPress 3.9.1'
git push origin master
Let me break that down:
cd wp — move into the WordPress submodule directory.
git fetch — Pull down the latest changes from tracked branches.
git fetch --tags — Pull down the new tags. You do steps 2 and 3 in this order because otherwise you might have a tag that points to a commit that you don't yet have in your repo.
git checkout 3.9.1 — Checkout the 3.9.1 tag.
cd ../ — Move back into the main directory. At this point, the wp subdirectory will show as having changes, since it points to a different commit.
git add wp — Tell your main repo to stage the WordPress submodule repointing.
git commit -m 'Update to WordPress 3.9.1' — Commit that change git push origin master — Push your master branch (change if using a different branch) up to your origin remote (change if using a different remote).
You probably noticed that there
is only one variable here — the version number. So You could wrap that
up into a bash script that you check into your root directory. And
then you could just do something like: ./wpupdate 3.9.1. Or you could
write a script that iterates through a bunch of WordPress site
checkouts and does this process on each of them (I've done exactly
that).
I will also add that from the wp folder you can enter git tag to see a list of tags, this way you can make sure you get the latest one.

How to Upgrade and Deploy WordPress Install as a Git Submodule?

I am using a WordPress directory struture similar to Mark Jaquith's WordPress Skeleton, which has WordPress in a separate directory from the content as a submodule:
/content
/wp
/local-config.php
/wp-config.php
/index.php
I also use git and post-receive hooks to push my code changes up to my live server. It all works great except for when I try to upgrade WordPress and push that up to the live server.
This is how I setup the repo on my local machine and the remote server:
Local Machine
cd /www
git init .
git submodule add git://github.com/WordPress/WordPress.git wp
git commit -m "Add Wordpress submodule."
cd wp
git checkout 3.5
After checking out the tag, I get a warning from git about being in a 'detached HEAD' state. Since I don't plan on making any commits to WordPress, I don't think that should be an issue.
cd ..
git commit -am "Checkout Wordpress 3.5"
Remote Server
git init --bare
cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/home/public git checkout -f
chmod +x hooks/post-receive
git remote add web ssh://user#server/home/private/code/wordpress.git
git push web +master:refs/heads/master
I get this error:
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'ssh://userserver/home/private/code/wordpress.git'
After some googling, it looks like I can use this command to sync up the master branch up to the server (I have no idea how this works)
git push web +master:refs/heads/master
This doesn't help me though because I don't want to track master, I want to track a release tag, 3.5. Some more googling got me to this command:
git push web +3.5~0:refs/heads/master
To upgrade the submodule, I do this:
cd wp
git fetch && git fetch --tags
git checkout 3.5.1
git push web +3.5.1~0:refs/heads/master
Am I doing this correctly? All the tutorials I see for this just have git push web and they're done. Most don't even cover upgrading the submodule. This does work but I don't feel comfortable using this weird push syntax if I don't have to.
How do I push this detached HEAD state up to the server correctly?
I've also tried this using a branch with git checkout -b mywp 3.5 but when it comes time to upgrade, I don't know how to bring in the new 3.5.1 tag into my mywp branch.
Asked this on WP Answers, but it might be more appropriate here.
On the remote server try:
git submodule update --init --recursive
This will update all your submodules recursively
You can also issue:
git fetch --tags
This will update your local tags fetching updated list from the central remote repo.

Resources