I have a repo setup in Bitbucket (origin) and a clone on my local machine for dev work and a clone on my production server (a VPS). Currently my workflow is:
- I commit my changes in sourcetree and push them to back to the origin (bitbucket)
- SSH into my VPS and pull the repo changes from origin
I would much rather setup another remote in bitbucket and be able to push straight to my VPS via sourcetree rather than having to SSH in.
a) able to be done
c) how do i do it - I worked out how to create a new remote in sourcetree but I can't for the life of me work out what the path is for my VPS. I'm using https because I couldn't get bitbucket and my VPS to be friends with SSH keys.
I appreciate any help, thanks,
Provided your VPS has got git installed then you can do the following:
Figuring out the path to your VPS will be figuring out what your hostname is, to do this just enter "hostname" at the terminal. Then from there just enter "cd /" and then go through your directory structure until you find the folder where your repository is. You say you need to SSH in, but actually the push will manage the SSH as you're doing it through the SSH protocol.
When you set up the VPS git directory you want to do "git --bare init" because if it's already initialised and not bare then you can't just push to it. Then from your client you can just push to that repo and the changes will be in there. You'll also be able to make changes from there too if needs be.
So to summarise:
I hope I've covered everything needed. The only thing I should note is you can't push to multiple remotes at once in SourceTree at the moment (I think this is logged in JIRA as a feature request) so you'd have to push to both remotes. Also, I wonder why your VPS hasn't got access to pull from the default remote on BB?
Have a try at completing some of the steps, if you get stuck feel free to ask more questions.
Thanks so much, that was an epic answer - It made perfect sense and I got the path fixed. I have two further questions now:
1) Is the correct path - ssh://username@hostname/path/to/repo OR ssh://username@hostname/path/to/repo/repo.git ??
I.e. is it the folder the repo is in I'm targeting or the .git folder itself inside the folder my repo is in.
2) With my VPS I had ssh-ed in previously and cloned the repo from origin (bitbucket) and then run 'git pull origin' on that repo in my VPS via ssh. If I then setup a remote in Sourcetree and run the 'push' command, will it just push the changes to my already cloned repo, or will it try to push a whole new clone version to the path I specified?
Thanks so much again,
1) The former will do it, it detects if there's a .git folder to determine if it's a valid git repository
2) It should push all changes since the changes from your last pull. This is why you need to do git init --bare on the VPS because it's a remote. When it goes to push there it won't know precisely what to push so you'll likely get an error. You could set up a test repo on the VPS to test this by just a) copying your existing repo into a test repo to see if the push works or b) do git init --bare. This way, you shouldn't worry about damaging your repo on the VPS (that shouldn't happen, but I always play it safe). If you look at your log view in ST you'll see it says something like "4 ahead" - it knows how many commits have happened since the last pull, so that's what it's pushing. Mercurial push actually shows you what's being pushed. There's a much detailed explanation of this here: http://stackoverflow.com/questions/4179842/predict-how-much-data-will-be-pushed-in-a-git-push
Hope that helps :)
Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
We're bringing product updates and pro tips on teamwork to ten cities around the world.Save your spot