share git repo between two computers locally - ios

I'm working on an Xcode project and my brother wants to start helping out. I have the .git folder in my Xcode project directory, how can my brother pull / push / commit to / from my computer? Do I have to use OS X server and put the repo inside of there, or is there a simpler way to do this?

One simple option is to enable "remote login" in sharing, which enables ssh, then you can use the ssh protocol to clone the repository. Remote login preferences will tell you:
To log in to this computer remotely, type "ssh username#computer.local".
username#computer.local will be replaced with your username and hostname. In terminal, use:
git clone username#computer.local:[path]
on your brothers computer to clone the repo to him, where [path] is the path to the folder containing the repository. You will need to enter your password, and you will need to enter it in order to copy changes back later with git push or whatever.
You can set up passwordless ssh with private keys, but bear in mind that by doing this you are effectively giving your brother entire control of your computer.

If you want to push code between two non-bare repositores, I recommend having a look at git-annex.
It is usually used for syncing large files between repositories, but it also contains a nifty way of syncing non-bare repositories (pushes go to synced/master branch that is automatically merged).

Basically, if one can write a ls path or ssh [user#]host:path ls command that would list your repository, then you can use the corresponding git clone [[user#]host:]path [optionalNewName] to clone from it.
Also if he (or you) is working on the same local machine, or has access to the local filesystem, one need only point to either the .git directory or the directory containing the .git directory.
To make clone a repository into another directory:
git clone . ~/2015Archive/repositoryB # copy pwd's repository elsewhere
git clone .git ~/2015Archive/repositoryB # same
git clone ~path/path/repositoryA . # clone other repository into pwd
git clone /home/brother/2015/projects/CoolProject ~/WORK/BrosCode
# with ssh from a remote machine
git clone me#brosmachine:/home/brother/projects/CoolProject WORK/BrosLameCode
git clone me#brosmachine:../brother/projects/CoolProject WORK/BrosLameCode
If you change into the target repository and do a git remote -v it will show you an absolute path to the 'origin' from which it was cloned. If it was a local dir, it will be just a plain, absolute path. If it was accessed through ssh, it will be a ssh [user#]host:path identifier.

Related

how to add existing non-git project to bitbucket

I created a project using angular cli. Project is in directory dw-ng2-app and it has several files generated by angular cli. I want to create a Bitbucket repository for this. My confusion is, when I create a repository in Bitbucket, it gives me 3 options
I create a README and .gitignore file. I cannot use this option as
then when I try to sync the local project with repository, I get
error that there is no common history
I selected option of starting
from scratch. The web page listed the commands I should run to clone
and upload, eg git clone git#bitbucket.org:username/angularcli.git
but this creates a new directory on my local machine named
angularcli which has .git directory. I am not sure if I can use this
option as my project is in different directory and moving it to
angularcli directory might affect it (not sure)
3rd option is to
mention that I have an existing project. Then I am prompted to use
the command git remote add origin
ssh://git#bitbucket.org/username/angularcli.git but that doesn't
work as my current project directory is not a git repository
How can I move the angular cli project to bitbucket? Should I have created the repository first and then created angularcli project in the generated directory?
There are a couple of ways to do this, but the simplest may be to simply make your current project directory, a git repository.
Go to your project directory
cd dw-ng2-app
Initialize git repository
git init .
Add your current project to be tracked
git add --all
Make your initial commit
git commit -m "Initial commit for Angular project"
At that point, you can use the third, "existing project" option within BitBucket.
After you've created a new repo there, you can see its URL and use that to track your new repository with your local one
git remote add origin https://username#your.bitbucket.domain:7999/yourproject/repo.git
git push -u origin master
[Here's a complete writeup from BitBucket if you need.][1]
note - I used git add . originally in my example, and BitBucket recommends git add --all. Either of these will work fine in your case.
[1]: https://confluence.atlassian.com/bitbucketserver/importing-code-from-an-existing-project-776640909.html
If you've created project using angulat-cli then it automatically created project with git initialisation. It also commits initial changes locally.
So you just have to add remote origin and push the content.
-If repository is not initialise as git repository then:
cd dw-ng2-app
git add --all
git commit -m "commit message"
git push -u origin master
-If already initialise with git repository.
First of all go to directory dw-ng2-app : cd dw-ng2-app
add remote to your repository.
git remote add bitbucket https://username#your.bitbucket.domain/yourproject/repo.git
push the changes:
git push -u origin master
here's master is name of branch in which you want to push the content.

Split up Git Repository

I have a git repository that contains two directories:
src: A full Rails app
devbox: Files to build a vagrant machine and provision using an Ansible script
I wish to split these out to two separate repositories so I have one solely containing my app and another containing the vagrant devbox.
This SHOULD allow me to add the app repo as a git submodule inside the devbox one in order to be worked on but at the same time allow Capistrano to grab the source from the app repo without any faffing around to only get a subdirectory of the full combined repository.
Any thoughts about how to go about splitting the current repo up? I'm just a bit unsure where to begin.
move the devbox folder out of the repo.
mv devbox ~/Projects/
move the src folder out of the repo.
mv src ~/Projects
create two empty repos on your github account for both devbox and src
initialize devbox as git repo cd ~/Projects/devbox && git init
Add the git remote. Instructions provided when you created the git repo on github. git add remote ...
Push the repo to github git commit -am'initial commit' && git push origin master
Repeat steps 4-6 for src

Add project files from Local machine to Github Repository

I am working on an iOS project. our employee has created a repository say app and we have a master branch by default. employee has created another branch say "second" now I need to upload my project files from my machine to Github repository's Branch "Second" looking into a lot of tutorial and didn't understood what and how to do that... This question may have already asked but sorry didn't helped any...
At first, make full backup of your project, so
you can restore it if something goes wrong.
If you have local git repository (in terminal you can see .git and .git**** files after execute "ls -la" command in project directory):
1) Open your project folder with your local git repository in Terminal and add your Github repository as origin:
$ git remote add origin https://github.com/your_user/your_repo.git
(This url you can see at Github repo)
2) Push all your local branches onto repository:
$ git push --all origin
If you do not have local git repository:
1) Create new folder, go inside it and in Terminal execute this:
$ git clone https://github.com/your_user/your_repo.git
2) Copy all your iOS project (with inner files/folders/etc) into that folder
3) Add all your local files into local git repo:
$ git add .
4) Commit all changes:
$ git commit -m initial
5) Push all your local branches onto repository:
$ git push --all origin
Also see Github help:
https://help.github.com/articles/adding-a-remote/
https://help.github.com/articles/pushing-to-a-remote/

How to upload a project to GitHub

After checking How can I upload my project's Git repository to GitHub?, I still have no idea how to get a project uploaded to my GitHub repository.
I created a repository and want to upload my project to it.
I've looked on the repository page for an upload button of some kind, but I haven't seen anything of the sort.
I've looked at the links provided so far, but I'm still getting nowhere. They mention command line; is that Windows command line or Git Bash? Because I can't get either to do anything.
I also tried using the Git GUI, but when I select the folder I want it says that it's not a Git repository...does it need to be zipped up? I tried adding the .gitconfig file in the folder, but it doesn't make a difference.
GitHub released a native Windows client which makes all the below steps redundant.
You can also use Sourcetree to get both Git and Mercurial setup on Windows.
Here is how you would do it in Windows:
If you don't have Git installed, see this article on how to set it up.
Open up a Windows command prompt.
Change into the directory where your source code is located in the command prompt.
First, create a new repository in this directory git init. This will say "Initialized empty git repository in ....git" (... is the path).
Now you need to tell Git about your files by adding them to your repository. Do this with git add filename. If you want to add all your files, you can do git add .
Now that you have added your files and made your changes, you need to commit your changes so Git can track them. Type git commit -m "adding files". -m lets you add the commit message in line.
So far, the above steps is what you would do even if you were not using GitHub. They are the normal steps to start a Git repository. Remember that Git is distributed (decentralized), meaning you don't need to have a "central server" (or even a network connection), to use Git.
Now you want to push the changes to your Git repository hosted with GitHub. You do this by telling Git to add a remote location, and you do that with this command:
git remote add origin https://github.com/yourusername/your-repo-name.git
*Note: your-repo-name should be created in GitHub before you do a git remote add origin ...
Once you have done that, Git now knows about your remote repository. You can then tell it to push (which is "upload") your committed files:
git push -u origin master
Follow these steps to upload a project to GitHub:
git init
git add .
git commit -m "Add all my files"
git remote add origin https://github.com/yourusername/your-repo-name.git
Upload of project from scratch require git pull origin master.
git pull origin master
git push origin master
git push --force origin master
if you have problems uploading!
Here I explain how I did it on Windows.
Make sure to install Git and GitHub.
After installation is complete, open Git Bash.
So a window like below is going to pop up:
Go ahead and type cd ~ to make sure you are in the home directory. You can check the address that you are in it by typing pwd;
Now you need to create a GitHub account. After creating a GitHub account, go ahead and sign in.
After you signed in, on the top right click on the + and choose “New Repository”
Then in the opened window, type the name that you wish to have for the repository in the “Repository name” box. Add “Description (optional)” if you like, and mark “Initialize this repository with a README”. Then click on “Create repository”.
Now go to your C drive; create a new folder and name it “git”. Now go to the “Git Bash” window; change the directory to c drive by typing cd ~; cd /c.
If you type ls there it would show you the folders there. Make sure it shows the Git folder there:
Now go back to the browser; go to your GitHub page, click on the repository that you made, click on “Clone or download”, and copy the address that shows there (by choosing copy to clipboard).
Now going back to “Git Bash”. Use the command cd git to go to the git folder; now write the following commands to connect to your GitHub (enter the username and password of your GitHub when it asks you):
git config --global user.name "Your Name"
And then: git config --global user.email youremail#domain.com.
Next type: git clone (URL), instead of the (URL), type the address of the GitHub repository that you copied from your GitHub page; (e.g., git clone https://github.com/isalirezag/Test.git).
Now if you do ls command you will see your repository there. If you also open the Git folder that you have in your window you will see that your repository is added as a folder.
Now use the cd command to go to the repository: cd Test
Go ahead and copy and paste any files that you want to put in this repository in that folder.
In order to transfer the files to your repository you need to do following now:
Type git
add filename (filename is the file name that you want to upload) or you can type the command below if you want to add all the files in the folder:
git add .
Then type: git commit -m "adding files". And then: git push -u origin master .
And then you should be all set. If you refresh your GitHub account, the files should be there :)
Follow these steps to upload your project to GitHub:
git init
git add .
git commit -m "Add all my files"
git remote add origin https://github.com/yourusername/your-repo-name.git
Upload of the project from scratch requires git pull origin master.
git pull origin master
git push origin master
If any problem occurs in pushing, use git push --force origin master.
Follow these two steps:
Create the repository online using the link: https://github.com/new
Then link your local repo to the remote repo using the command: git add remote origin https://github.com/userName/repo.git
Here the repo.git will be your newly created remote repo.
This will work like a charm. No need to worry about the SSH or HTTPS ways. I first faced the same issue and spent hours for solution.
But this worked for me.
Easy-to-follow steps: git pull origin master or main will give a fatal error:
Couldn't find remote ref main
So below steps will work just fine.
git init
git add .
git commit -m "initial commit"
git remote add origin https://github.com/yourusername/your-repo-name.git
git branch -M main
git push -u origin main
This worked for me;
1- git init
2- git add .
3- git commit -m "Add all my files"
4- git remote add origin https://github.com/USER_NAME/FOLDER_NAME
5- git pull origin master --allow-unrelated-histories
6- git push origin master
Create a new repository on GitHub. To avoid errors, do not initialize
the new repository with README, license, or gitignore files. You can
add these files after your project has been pushed to GitHub. Open
Terminal (for Mac users) or the command prompt (for Windows and Linux
users).
Change the current working directory to your local project.
Initialize the local directory as a Git repository.
git init
#Add the files in your new local repository. This stages them for the first commit.
git add
# Adds the files in the local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'. Commit the files that you've staged in your local repository.
git commit -m 'First commit'
#Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.
At the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL. At the top of your GitHub repository's Quick Setup
page, click to copy the remote repository URL.
In the Command prompt, add the URL for the remote repository where your local repository will be pushed.
$ git remote add origin remote repository URL
# Sets the new remote git remote -v
# Verifies the new remote URL Note: GitHub for Windows users should use the command git remote set-url origin instead of git remote add origin here. Push the changes in your local repository to GitHub.
$ git push origin master
# Pushes the changes in your local repository up to the remote repository you specified as the origin.
Source attribution: Adding an existing project to GitHub using the command line
I assume you are on a Windows system like me and have Git installed. You can either run these commands by simple command prompt in the project directory or you can also use Git Bash.
Step 1:
Create a repository in Git manually. Give it whatever name you seem fit.
Step 2:
Come to your local project directory. If you want to publish your code to this new repository you just created, make sure that in the projects root directory there is no folder name .git. If there is, delete it.
Run command git init.
Step 3:
Run command
git add .
Step 4:
Run command
git commit -m YourCommitName
Step 5:
Run command
git remote add YourRepositoryName https://github.com/YourUserName/YourRepositoryName.git
Step 6:
Run Command
git push --set-upstream YourRepositoryName master --force
Please note that I am using the latest version of Git at the time of writing. Also note that I did not specify any particular branch to push the code into so it went to master. In step 6 the Git will ask you to authorize the command by asking you to enter username and password in a popup window.
Open Git Bash.
Change the current working directory to your local project.
Initialize the local directory as a Git repository: $ git init
Add the files in your new local repository. This stages them for the first commit: $ git add .
Commit the files that you've staged in your local repository: $ git commit -m "First commit"
At the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL.
In the Command prompt, add the URL for the remote repository where your local repository will be pushed : $ git remote add origin remote repository URL
Push the changes in your local repository to GitHub: $ git push origin master
First you have to create an account on GitHub
Then create a new project - name that project as you want and then your project URL is shown
Now copy the URL
Then open a Command Prompt and go to the directory or folder which you want to upload using cmd
Then type the following commands
git init
git add .
git commit -m "initial commit"
git remote add origin PASTE URL
git push -u origin master
Now check your GitHub account. The repository is successfully uploaded.
For complete guidance, you can watch this video.
It took me like 1-2 hours to realize that I'm supposed to create the repository at GitHub before trying to push my local files to GitHub (or whatever, Git service you're using).
After trying to push, errors were like:
remote: Repository not found.
fatal: repository 'https://github.com/username/project.git/' not found
I feel like an idiot, but I really would like to emphasize this for beginners like me. I just thought that my repository will be created automatically during the first push. I was so wrong.
You can see your remotes with this command:
git remote -v
Steps to upload project to Git:
Step 1 - open cmd and change the current working directory to your project location.
Step 2 - Initialize your project directory as a Git repository.
git init
Step 3 - Add files in your local repository.
add .
Step 4 - Commit the files that you've staged in your local repository.
git commit -m "First commit"
Step 5 - Copy the remote repository URL.
Step 6 - Add the remote repository URL as origin in your local location.
git add origin copied_remote_repository_url
Step 7 - Confirm your origin is updated or not.
git remote show origin
Step 8 - Push the changed to your GitHub repository
git push origin master.
I think the easiest thing for you to do would be to install the Git plugin for Eclipse. It works more or less the same as the Eclipse CVS and SVN plugins.
Make sure that Git is installed on your system. I'm explaining the process using windows OS [Although it shouldn't be OS dependent job]
Here is how I did:
Open the cmd (you can do with git bash as well if you've installed git bash).
Go to your project directory (where your project is located, it's essentially changing to directory either usiing cd path or through manual folder navigation).
Now type git init. This will initialize an empty repository if it is first time and Enter.
For example: git init
Now type git add <filename>(if specific file) or git add <filename1> <filename2> <filenameN> (if specific but more than one files) or git add . (if you want to add all files) and enter.
Now type git commit -m "commit message goes here" and enter.
(in case if you need to check the status you can do by typing git status) and enter.
Now type git remote add origin git_repository_url
(check git remote -v go check remote repository) and Enter.
Now it's turn to push it to the remote repository [essentially taking all the changes from local git to cloud(github) ...git push origin master and enter
(if you get error you push it forcefully by typing ...git push -f origin master and enter.
NOTE : master is the name of your master branch. If you've multiple branches, make sure that you select the name of the branch accordingly.
Now you're done with adding it to your remote repository from local computer. Refresh it and it will be there in your created repository's selected branch.
Probably the most useful thing you could do is to peruse the online book Pro Git. It's really a pretty decent read and gives you the conceptual context with which to execute things properly.
Follow the instructions from RishiKesh Pathak. You can even short the push command by inserting this command line one time only:
git config --global push.default simple
So next time instead of using git push origin master you just need:
git push
See details here.
Download Sourcetree.
It is available for Windows 7 (and later) and Mac, and it is highly recommended to upload files on GitHub via the interactive UI.
The best way to use Git is to actually start Gitting. Try out this website which makes you go step by step on what are the essential ways for performing functions on command line for pushing a project on GitHub.
This is called try.github.io or you could also take up a course on Codecademy.
I did as follows;
git init
git add .
git commit -m "Your_message"
git remote add origin #your_git_repository
git push -u origin master
Of course you have to install Git.
We need Git Bash
In the Git Bash Command Section:
ls
It will show your default location.
CD "C:\Users\user\Desktop\HTML"
We need to assign the project path.
git init
It will initialize the empty Git repository in C:\Users\user\Desktop\HTML
ls
It will list all file names.
git remote add origin https://github.com/repository/test.git
It is your https://github.com/repository/test.git is your repository path
git remote -v
To check whether we have fetch or push permission or not
git add .
If you use . then it means whatever we have in the particular folder publish all.
git commit -m "First time"
git push -u origin master
Upload a project from Visual Studio Code to GitHub
To upload your project in GitHub using Visual Studio Code, follow the following steps.
Open the Visual Studio Code. if you don't have the VSCode download: Download Visual Studio Code
In VSCode go to File-->Open Folder..
Go to Terminal-->New Terminal
Execute the following commands one by one after one another in order
git init
git add .
git commit -m "First Commit"
git remote add origin https://github.com/yourusername/your-repo-name.git
git push origin master
Note: in the above command git remote add origin https://github.com/yourusername/your-repo-name.git please change the bold sections with your GitHub account name and your repository name.
You need an SSH connection and GitHub init into your project. I will explain under Linux machine.
Let's start with some easy stuff: navigate into your project in the terminal, and use:
git init
git add .
git commit
Now let's add SSH into your machine:
use
ssh-keygen -t rsa -C "your_email#example.com"
Copy the public key, and then add it to your GitHub repository:
Deploy keys -> add one
Back to your machine project, now launch:
git push origin master
if there is an error, configure your .github/config file by
nano .github/config
And change the URL to the SSH one by:
url = git#github.com:username/repo....
And that's it.
Try using Git Bash to push your code/make changes instead of uploading files directly on GitHub (it is less prone to errors and is quite comfortable at times - takes less time as well!). For doing so, you may follow the below given steps:
Download and install the latest version of Git Bash from here.
Right-click on any desired location on your system.
Click “Git Bash Here”.
git config --global user.name “your name”
git config --global user.email “your email”
Go back to your GitHub account – open your project – click on “clone” – copy HTTPS link.
git clone PASTE HTTPS LINK.
A clone of your GitHub project will be created on your computer location.
Open the folder and paste your content.
Make sure content is not empty.
Right-click inside the cloned folder where you have pasted your content.
Click “Git Bash Here” again.
You will find (master) appearing after your location address.
git add .
Try git status to check if all your changes are marked in green.
git commit --m “Some message”
git push origin master
You just need to know few command im cmd to push or pull any directory to/from github.
Command to push/upload any project or code to the git hub.
First reach to the working directory or project directory which you need to upload.
to check the correct working directory
ls
to initialize the git in the directory
git init
to the check that git init worked or not
ls -a //this command shows hidden files
Using above command you will find file added in you directory.
./ ../ .git/
the above is not a command you can skip it.
Now add the files of working directory to commit
git add .
then use commit command and name that commit for reference
git commit -m "Commit Name"
Before final step you need to go to the github website and create a new repository and copy the url of the repository
git remote add main https://github.com/username/repositoryName.git
now command to upload the directory
git push -u main
Note: the name "main" is the name that can be change as per user
For uploading a new project into Git (first you need to have the local code base of the project and the Git repository where you will be uploading project. In Git, you need to have your credentials).
List item
Open Git Bash
Go to the directory where you have the code base (project location)
cd to project location
cd ////**
Then here you need to execute Git commands.
git init
Press Enter then you will see something like this below.
The initialized empty Git repository in ://****/***/.git/, so git init will initialize the empty Git repository at local
git add .
Press Enter
The above command will add all the directories, subdirectories, files, etc.
You will see something like this:
warning: LF will be replaced by CRLF in **************.
The file will have its original line endings in your working directory.
git commit -m "first commit"
Press Enter. -m provided option for adding comment.
It will commit the code to the stage environment.
You will see some thing like this:
[master (root-commit) 34a28f6] adding ********
warning: LF will be replaced by CRLF in c*******.
The file will have its original line endings in your working directory.
27 files changed, 3724 insertions(+)
create mode 100644 *****
create mode 100644 *****
create mode 100644 *****
git remote add origin
http://username#git:repopath.git
Press Enter. This will add to the repository.
git push -u origin master
Press Enter.
This will upload all from local to repository in this step you need to enter password for the repository where you will be uploading the code.
You will see some thing like this below:
Counting objects: 33, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (32/32), done.
Writing objects: 100% (33/33), 20.10 KiB | 0 bytes/s, done.
Total 33 (delta 14), reused 0 (delta 0)
To http://username#git:repolocation.git \
[new branch] master -> master
Branch master set up to track remote branch master from origin.

how do I deploy multiple branches to different directories via git push?

In production, I maintain two sites - beta and release. Each points to a different directory via a soft link (e.g.)
beta_public_html -> /home/scott/myapp/trunk/public
public_html -> /home/scott/myapp/branches/1.2.3/public
I'm a longtime svn user, moving to git. I'm used to deploying via svn update and changing the soft link on a new branch, things are pretty simple.
Now I'm moving to git. I still need to have the two soft links (it's a Rails app using Passenger), though now I want them to point to two different git branches ("beta" and "release", say). And I want to be able to update them via git push (or git pull).
Question Part 1: I'm not sure the best way to do this.
The way I had started to do it was to just deploy to two different remotes, e.g.
git push ssh://scott#x.com/home/scott/myapp-beta beta
git push ssh://scott#x.com/home/scott/myapp-release release
But this doesn't work because push doesn't update the working tree by default.
So I go into the remote directories and run git reset --hard the first time, and it pulls the working tree. But I push again and I can't get the new push to show up - it just stays at the initial one.
(BTW, note that I can't seem to push to "myapp-beta.git" - that fails, I have to push to the directory name. I am worried that this is part of the problem, but I don't know what I did wrong here.)
So, if the answer to Question 1 is that my method is fine, Question Part 2: what's wrong with what I'm actually doing? If there are hooks I should be using, can someone point me to them?
(An answer to Question 1 that says "run these seven manual steps" will not be a terribly useful answer, seeing as svn checkout + ln -s are two steps.)
Thanks. I want to get back to writing code.
The article Git push is worse than worsless has an interesting discussion about a similar issue.
One of its solution and conclusion involves:
a bare repository on the production server
a cloned repository with a hook to pull what has been pushed into the bare one
So in your case,
one bare repo on which you can push beta and release branches
two cloned repo 'beta' and 'release' with a hook to pull their respective branches from the bare repo.
In short: one step: git push. No more link to manage (since the directory no longer represent a branch in Git, unlike SVN)
Regarding the hook part, a post-receive hook in the bare repo could be all what you need
See Git Tip: Auto update working tree via post-receive hook
$ cd bare
$ chmod +x .git/hooks/post-receive
with a post-receive hook like
#!/bin/sh
cd ../../beta
env -i git reset --hard
cd ../../release
env -i git reset --hard
Note:
the post-receive hook starts out with the GIT_DIR environment variable set to the repo/.git folder, so no matter what path you 'cd' into it will always try to run any following git commands there.
Fixing this is simply a matter of unsetting the GIT_DIR.
'env -i' does just that: it ignores the inherited environment completely and uses only the supplied variables and values.
The solution is to push to single repository, which would employ update or post-receive hook.
There are a few separate possibilities to create two checkouts, which can be used in hook (on server). Going from most lightweight:
If you don't need for those two checked out directories (checked out versions) to actually be git repositories, you can simply use git-archive to export two snapshots (two branches)
git archive --format=tar --prefix=public_html/ master | (cd /var/www/html && tar xf -)
git archive --format=tar --prefix=beta_public_html/ devel | (cd /var/www/html && tar xf -)
where 'master' and 'devel' are names of branches that you wanted to have checked out. Note that --format=tar is not strictly speaking needed, as tar format is default for "git archive". You might also want to remove old contents ("rm -rf public_html/" before "tar xf -" in first line, joined with "&&", and similarly for the second line).
Alternate way of exporting files would be to use low-level commands "git read-tree" (which writes tree to index) and "git checkout-index" (which copies files from index to working area).
In this solution the repository you push into can (and should) be bare, i.e. without working directory itself.
Another solution would be for the repository you push into to have two working directories, which can be created using git-new-workdir script from contrib/workdir. Each of those working areas would have be a checkout of appropriate branch of this repository.
Then update or post-receive hook would unset GIT_DIR, go to those working areas (public_html and beta_public_html), and do "git reset --hard" there.
In this solution "checkouts" would have some git-related metainfo in them (in hidden .git directory).
Yet another solution would be to have two (additional) slave repositories. Pushing into main (master) repository would then (via hook) either push into those two slave repositories, where their hooks would do "git reset --hard" or equivalent, or go to those two slave repositories and do a "git pull" from master there.
Those two slave repositories would be non-bare, and can be [directly in] public_html and beta_public_html. In this solution "checkouts" would be full-fledged git repositories itself.
You can improve this setup by having those slave repositories to have "alternates" (alternate object database) to point to master repository (i.e. be cloned with "git clone --shared ..."); without this object database in slaves starts hardlinked to master. This of course is possible only if master and slaves are on the same filesystem.
Note this solution allows for master repository to be on different host than slave repositories. (although I guess this is flexibility you don't need).
Finally you can instead of current setup deploy gitweb or some other git web interface (see InterfacesFrontendsAndTools and Gitweb wiki pages for a partial list), so that your users can browse different versions and different branches of your repository at their leisure.
In gitweb (and I guess also in other git web interface) thanks to path_info URL support you can view files in browser, and follow links correctly (if they are local), see e.g. git.html from 'html' branch of git.git repository at repo.or.cz.
P.S. "git push" does not update working directory in remote repository by default, because if somebody is working in the non-bare repository you push into, such sideways push can be very unexpected and lead to loss of work.
I use a post-receive hook like this to publish my website, because Git does not touch the working directory when doing a push. The remote repository is a non-bare repository, i.e. it has a working directory.
if [ -n $GIT_DIR ]; then
# Current dir is "<reporoot>/.git/", but we need to run reset at "<reporoot>/".
# Clearing GIT_DIR is needed, or reset will fail with "fatal: Not a git repository: '.'"
unset GIT_DIR
cd ..
fi
git reset --hard
(BTW, note that I can't seem to push to "myapp-beta.git" - that fails, I have to push to the directory name. I am worried that this is part of the problem, but I don't know what I did wrong here.)
When creating a bare Git repository (git init --bare) which does not have a working directory, it is a convention to name the directory "something.git". When having a non-bare repository, the repository is actually in the ".git" subdirectory, so the full path is "something/.git". It seems that in either case you can leave out the ".git" part and Git will detect it automatically.
I'm not really opposed to the other solutions, but I think there's a less hack'ish "Git way" to do this. Here's what I would do:
On my server, I'd set up a sort of a centralized repository (to be managed by Gitosis or some such thing).
From the client end, I'd constantly pull from the repository, make changes and push back. Branches are ofcourse, managed automatically.
I'd pull the required branch from Gitosis into public_html/ beta_public_html of the server. I'd keep it in sync with Gitosis periodically using a Cron job. If you don't like the Cron job idea, you could always use some sort of a hook + script as the others have pointed out.

Resources