How to clone the latest stable branch to a dir via github? - wordpress

I want to clone the latest stable version of WordPress from Github, via a shell script. It is simple to get the unstable master branch:
git clone git://github.com/WordPress/WordPress.git
But how can I get the highest numbered stable release via a script, not manually checking out the code. E.g., using deployment shell script or deployment tool such as Fabric.
Edit: I clarified the text to better indicate the intent that I meant how to do this from a script, not manually.

Clone from git and change to the WordPress directory
git clone git://github.com/WordPress/WordPress.git
cd WordPress
Then list out the branches..
git branch -r
This gives something like...
origin/1.5-branch
origin/2.0-branch
...
origin/3.4-branch
origin/HEAD -> origin/master
origin/master
Check out the branch you want...
git checkout 3.4-branch
Branch 3.4-branch set up to track remote branch 3.4-branch from origin.
Switched to a new branch '3.4-branch'

Here's what I actually ended up doing, which is included in a Fabric fabfile I have on Github:
git clone git://github.com/WordPress/WordPress.git .
git checkout $(git describe --tags $(git rev-list --tags --max-count=1))
It clones the repo like normal, then does some shell magic to find the latest tagged version of WordPress (Which is where the stable branches live.)

Can you try a git checkout master ?

git branch -r will show you all the remote branches
git checkout --track <local_branch> <remote>/<remote_branch> will setup a local branch that is tracking the remote branch in order to push or get new updates.

you can use this command after git clone
git checkout stable

Related

Creating a git repo for an existing R project - "fatal: Couldn't find remote ref master" error

I want to finally start using version control for my R projects. I started following this guide, created an empty repo, but the problem started when I got to the command line part.
First I did:
git remote add origin https://github.com/username/repo_name.git
But after I type:
git pull origin master
I get this error:
fatal: Couldn't find remote ref master
Now, if I try the following:
git remote -v
I get:
origin https://github.com/username/repo_name.git (fetch)
origin https://github.com/username/repo_name.git (push)
So something is working. I am new to git and not sure about where the problem is.
As an attempt to fix the problem, I added one file for the repository (file.R) but apart from that, the repository is empty. I get the same error as before.
And if I try git branch -r on the terminal I don't get anything in return.
If you started by creating an empty repo in GitHub, then the default branch is no longer master. The default branch is now main.
If you started by creating a new repo locally using git init, then check what your default branch is using git branch. This should show you either a main or master branch.
It may be easier to create the repo in GitHub with a simple README.md and .gitignore, then clone that repo to another folder. Move your code into that repo, add and commit everything, then push your code to GitHub.

alternative approach to setup github project with git clone

For some projects stored on github.com, they suggest the following commands for setup,
Clone this repository: git clone https://github.com/projectA/projectA.git
Initialize all submodules: git submodule update --init --recursive
My development environment is built on the enterprise network behind the firewall, which does not allow me to use git clone and git submodule. With respect to this kind of scenario, what are the alternate approach to solve that?
You can try and clone a repo at home, use git bundle in order to generate one file (with all the repo history in it) and copy that file somewhere accessible from your enterprise network.
That way, you can clone from that file, and still get the repo full history.

Pushing files to a BitBucket repo doesn't work

I'm new to git and would like to get started using bitbucket.org as a place to create a private repository. This can then be uploaded to the staging server using a service like ftploy.com as I understand.
I am following a tutorial on WPBeginner.com to set up a staging environment for my WordPress local website which I am developing. I set up git on the mac, ran git init on the theme folder and then added all the files using git add .
After that I made a first commit using git commit -m "message here" So far the process appeared to work. No feedback in the terminal though? I then added the line
git remote add origin https://bitbucketusername#bitbucket.org/bitbucketusername/repositoryname.git
Replacing bitbucketusername with mine and repository name with mine. Attempting to push the files to the bitbucket repository resulted in this error however:
error: --all can't be combined with refspecs
usage: git push [<options>] [<repository> [<refspec>...]]
-v, --verbose be more verbose
-q, --quiet be more quiet
--repo <repository> repository
--all push all refs
--mirror mirror all refs
--delete delete refs
--tags push tags (can't be used with --all or --mirror)
-n, --dry-run dry run
--porcelain machine-readable output
-f, --force force updates
--force-with-lease[=<refname>:<expect>]
require old value of ref to be at this value
--recurse-submodules[=<check>]
control recursive pushing of submodules
--thin use thin pack
--receive-pack <receive-pack>
receive pack program
--exec <receive-pack>
receive pack program
-u, --set-upstream set upstream for git pull/status
--progress force progress reporting
--prune prune locally removed refs
--no-verify bypass pre-push hook
--follow-tags push missing but relevant tags
If you have any thoughts on why this may be the case I would appreciate it
You should provide us the command you used to do your git push, but my guess is you did something like this:
git push --all origin master
As git is telling you, this can't be used that way. Here you are asking git to push everything to origin but then you specify a branch (the <refspec>), so it is confusing.
Either push all like this:
git push --all origin
or just your master branch like this:
git push origin master

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