adding version control Git to my already deployed wp website - wordpress

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

Related

How to upload local RStudio Project to Github including commit history?

I have a RStudio Project with a history of git commit history.
I would like to upload this Project incl. the git commit history to Github and see the commit history on Github.
I can create a new repo on Github and commit from RStudio, but this would not include
past commits i have locally.
What i tried:
I can upload a RStudio Project / package. But (all?) the git files are in a hidden Folder (OS: Windows 10) and i cant upload this hidden Folder to Github (get a warning / error message "This file is hidden").
Looked through https://happygitwithr.com/rstudio-git-github.html
All you should need would be to:
add an origin to your local repository referencing the new (empty) GitHub repository
push
That is:
git remote add origin https://github.com/<you>/<newRepo>
git push -u origin master
# or
git push --mirror
Add your GitHub url to the remote using the Terminal tab then push. https://articles.assembla.com/en/articles/1136998-how-to-add-a-new-remote-to-your-git-repo

Local alternate for Git with RStudio?

My colleague & I are starting on a R project, we both would be working simultaneously & interchangeable components of the model we are building. We can not use Git, as we do not want to put our code online, also it is not allowed by the organization. We also do not have a server of our own, what we have is some common shared drive. Is there a way, we can use a tool like Github/SVN completely locally, where both of us can push our code.
There are two options you can manage your R project with git repo.
Option 1: setup remote git repo in the shared directory
You can setup a remote git repo in the shared directory, and then add the remote repo as a remote for your local git repo, then you can push and push from the remote git repo. Detail steps as below:
First, in an empty folder of the shared directory (assume in \\share\path\gitrepo), execute:
git init --bare
Then add the remote repo as a remote for the local repo you are working.
Assume the local git repo (R project) is opened in R Studio, so you can add remote in R Studio terminal window or through git command line:
git remote add origin \\\\share\\path\\gitrepo
Note:
The count of slash \ in the remote repo url.
And the pull and push button is still disabled after adding remote repo since the local branch (maste) has not tracked the remote branch (origin/master).
Then you can commit changes and push to remote repo first time by:
git push -u origin master
After that (local master is tracking origin/master), the pull and push button will be enabled after refresh the git tool bar. And can pull/push by clicking the buttons afterwards.
Option 2: host the remote git repo to third-party private repo
If it’s ok for you to hosted your git repo to third-party, and do not let everyone has read permission, then you can create a private git repo in the third-party organization.
For bitbucket, it’s free to create private git repos, so you can host your git repo there.

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.

r studio fatal: No configured push destination

I'm trying to create a blog using R package blogdown.
The last step is to push my files to Github, and I clicked "Push Branch",
which gave me this error message:
I'm not very experienced with Git/Github integration with R Studio. Can somebody leave a detailed explanation of what to do?
Syntax
You add remote git server URL to local git repository config like this
git remote add origin your_git_repository_url
Example
At git local repository folder, release command:
git remote add origin https://github.com/donhuvy/java9.git
Learn more
https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes#_adding_remote_repositories (official reference document)
https://help.github.com/articles/adding-a-remote/

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