Stashing changes with Git

Sometimes you’ve started some work on your project, then realised you should have started a new branch.
Create a new stash, using

git stash

See Git Stash for more details
This resets the Head back to your last commit, and stores the changes made since then in a new stash. List the stashes you have using

git stash list

Switch to the new branch then use

git stash apply

to apply the changes. If you have lots of stashes, you can use stash@{2} if you have more than one stash. Dont forget to

git stash drop

after you’ve copied the stash to the new branch.

File uploads via shell script

I’ve been trying to upload files to my web server form my local computer. I wanted to write a shell script to automate this (it also ties in with resizing images and writing .txt files to be uploaded).
I found scp to be not very useful for this. The problem is the resulting ownership of the files. With scp, you log in to your remote server via ssh. I have my ssh pretty securely (I hope!) locked down, so only a single user can log in, and that is only with authenticated keys. This means that when I upload using scp the files are owned by the user that uploaded them. This in turn means that when my web server wants to access them, it can’t because it doesn’t own the files. You can’t change ownership of files unless you are root.
My solution to this was to find a method of using ftp over ssh. The advantage of ftp is that it authenticates as a user that has read and write access to the web files. Any files uploaded by the ftp user, are automatically accessible to the web server, at least on my set-up. So here is how my eventual script looked;

#Upload via lftp


#I'll copy the files to my server from this folder
cd "/path/to/current/local/directory"

#The EOF bit passes input to the command prompt once logged in
# mput * copies all the files in the current working folder.
lftp -du $ftpUser,$ftpPass $ftpHost <<EOF
cd web/images/stories
mkdir "$rname1-$rname2"
cd "$rname1-$rname2"
mput *