Skip to content

Instantly share code, notes, and snippets.

@huzaifaarain
Last active December 4, 2018 12:47
Show Gist options
  • Save huzaifaarain/6b8203c3fc586d8e5f47a0e515763eb3 to your computer and use it in GitHub Desktop.
Save huzaifaarain/6b8203c3fc586d8e5f47a0e515763eb3 to your computer and use it in GitHub Desktop.
Git Push From One Working Directory To Remote Working Directory Without Bare Repository

GIT: PUSH TO REMOTE WORKING DIRECTORY

In this gist we are about to push changes from one working directory to another working directory without bare repository

Lets name our directories one_working , second_working.

Lets create the one_working directory

mkdir one_working
cd one_working
git init
cat > index.html 
Hello World
Press Ctrl + C
git status
git add .
git commit -m "initial commit"

Lets create the second working directory and add some configurations

mkdir second_working
cd second_working
git init
git config receive.denyCurrentBranch ignore
cd .git/hooks
cat > post-update 
git update-server-info
unset GIT_DIR GIT_WORK_TREE
cd ../ && git reset --hard
Press Ctrl + C
chmod +x post-update

Now move to the one working directory and add remote path and then push changes to second working directory

cd one_working
git remote add second_working /home/YOURUSERNAME/path/second_working
git remote -v
git push second_working master

Lets suppose there has been modifications in second working directory, what is the easiest way to compare both repositories ?

git remote update
git diff master second_working/master

Feel free to correct me in anyways.

By the way it's not recommended way to work on different directories, one must use the central repository which would be the bare to pull and push changes.

Regards, Huzaifa Arain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment