Setting up a git repo on a usb stick - RayGutt/PersonalWiki GitHub Wiki

Setting up a Git repository on a USB stick

### "Server side" - setting up the origin repo on the USB stick
matthieu@trex:/media/matthieu/extSSD/repos$ mkdir my_new_repo
matthieu@trex:/media/matthieu/extSSD/repos$ cd my_new_repo

matthieu@trex:/media/matthieu/extSSD/repos/my_new_repo$ git init
Initialized empty Git repository in /media/matthieu/extSSD/repos/my_new_repo/.git/

matthieu@trex:/media/matthieu/extSSD/repos/my_new_repo$ touch file_1
matthieu@trex:/media/matthieu/extSSD/repos/my_new_repo$ 
matthieu@trex:/media/matthieu/extSSD/repos/my_new_repo$ git add --all
matthieu@trex:/media/matthieu/extSSD/repos/my_new_repo$ git commit -m "added file_1"
[master (root-commit) b383ac8] added file_1
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file_1

# Doesn't work without this config option but I don't know why (yet)
matthieu@trex:/media/matthieu/extSSD/repos/my_new_repo$ git config receive.denyCurrentBranch updateInstead

### "Client side" - cloning and working on a local copy
matthieu@trex:~/repos$ git clone /media/matthieu/extSSD/repos/my_new_repo/
Cloning into 'my_new_repo'...
done.

matthieu@trex:~/repos/new_repo$ git remote add upstream /media/matthieu/extSSD/repos/new_repo/
matthieu@trex:~/repos/new_repo$ 
matthieu@trex:~/repos/new_repo$ 
matthieu@trex:~/repos/new_repo$ git pull upstream master
From /media/matthieu/extSSD/repos/new_repo
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> upstream/master
Already up to date.

matthieu@trex:~/repos$ cd my_new_repo/
matthieu@trex:~/repos/my_new_repo$ touch file_2
matthieu@trex:~/repos/my_new_repo$ 
matthieu@trex:~/repos/my_new_repo$ git add --all
matthieu@trex:~/repos/my_new_repo$ git commit -m "added file_2"
[master 910ed9d] added file_2
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file_2
matthieu@trex:~/repos/my_new_repo$ 
matthieu@trex:~/repos/my_new_repo$ git push origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 238 bytes | 238.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To /media/matthieu/extSSD/repos/my_new_repo/
   b383ac8..910ed9d  master -> master

## "Server Side": file_2 appeared
matthieu@trex:/media/matthieu/extSSD/repos/my_new_repo$ ls -l
total 0
-rwxrwxrwx 1 matthieu matthieu 0 janv. 14 16:52 file_1
-rwxrwxrwx 1 matthieu matthieu 0 janv. 14 16:57 file_2
matthieu@trex:/media/matthieu/extSSD/repos/my_new_repo$ 
# Without receive.denyCurrentBranch updateInstead, you get this error
# when trying to push to origin

matthieu@trex:~/repos/new_repo$ git push origin master
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 480 bytes | 480.00 KiB/s, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote: 
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote: 
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To /media/matthieu/extSSD/repos/new_repo/
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/media/matthieu/extSSD/repos/new_repo/'
⚠️ **GitHub.com Fallback** ⚠️