nb
nb copied to clipboard
nb sync setup
Hey, apologies in advance if I'm just not setting nb up right, but I've poured over the docs and it seems like I may run across a bug in the git handling.
Here are the steps I took:
-
Create a bare git repo
git init --bare
-
Initial set up sync
nb remote set ssh://my-git-url:/git/repo.git
-
Then I run
nb sync
for the first time, but I get an error that suggests that the repo couldn't find a master branch.
Syncing: home...! Remote branch not found: master
! Sync failed.
To fix this I run nb git push -u origin master
, then I am able to nb sync
successfully.
The problem comes up when I use multiple notebooks:
After creating a new notebook, I run nb remote set
using the same git repo as before, however when it syncs, it winds up merging the two notebooks together.
My workaround for this has been, for each new notebook i create, I also need to add the repo but set new branch to be the same name as the notebook. However this feels like a hack.
The docs aren't super clear on this, but is nb expecting a separate git repo for each notebook?
Hi @alexxhenry !
To answer the second question first: each notebook in nb
is a separate git repository. Most things in git operate on a repository level, so nb is designed around leveraging this to provide notebooks with separate histories and different syncing and sharing configurations, also enabling local notebooks and notebook archiving. So a notebook in nb
is an individual git repository.
That said, I’m working toward supporting the use of a single repository for multiple “notebooks” and there is an open issue for that.
Regarding the first issue, it could be the same as #61 and #70. See my comment in #61 for details. I plan to go through and update the branch handling logic for this as soon as I can.
Let me know if this answers your questions!
Hey William.
Thanks for the response. I didn’t mention it earlier, but I am totally smitten with nb! I really appreciate the work. I’m also relatively new to bash, so I’ve been learning quite a bit from you just by looking over the source code.
Regarding issue 61, yes, that’s the same. Sorry I didn’t see that sooner, I just assumed I was doing it wrong. The one caveat, is that even though I’m using master as my default in the global settings, I still need to run nb git push master
(master being my default).
FWIW, since I’ve been using a bunch of notebooks and often switch between them, I wrote a function workaround sourced from my .bashrc which does some git branch handling and works well for me. (Pardon the lazy use of awk).
nn is a function
nn ()
{
local notebook="$1";
if [[ $# -eq 0 ]]; then
nb notebook | awk '{print $1}';
else
if [[ $# -gt 1 ]]; then
echo "Usage: nn <notebook>";
echo "Notebook check and use. Switches current notebook.";
echo "Creates a new notebook if one dosent exist.";
else
if [[ -d ~/.nb/"$notebook" ]]; then
nb notebook use "$notebook";
nb git checkout "$notebook";
else
read -r -p "Notebook "$notebook" dosen't exist. Would you like to create it? <Y/n>" prompt;
if [[ $prompt =~ [nN(o)*] ]]; then
echo "Exiting. "$notebook" not created.";
echo "Current notebook is set to $(nb notebook current)";
else
nb notebook add "$notebook";
nb notebook use "$notebook";
if [[ ! -f ~/.nb/.git_repo ]]; then
echo "Sync is not set. Please add a git repo" 1>&2;
echo "to ~/.nb/.git_repo." 1>&2;
return -1;
else
local nb_git_repo;
read nb_git_repo < ~/.nb/.git_repo;
nb remote set $nb_git_repo;
nb git checkout -b "$notebook";
nb git push --set-upstream origin $notebook;
fi;
fi;
fi;
fi;
fi
}
On Dec 27, 2020, at 10:21 AM, William Melody [email protected] wrote:
Hi @alexxhenry !
To answer the second question first: each notebook in nb is a separate git repository. Most things in git operate on a repository level, so nb is designed around leveraging this to provide notebooks with separate histories and different syncing and sharing configurations, also enabling local notebooks and notebook archiving. So a notebook in nb is an individual git repository.
That said, I’m working toward supporting the use of a single repository for multiple “notebooks” and there is an open issue for that.
Regarding the first issue, it could be the same as #61 and #70. See my comment in #61 for details. I plan to go through and update the branch handling logic for this as soon as I can.
Let me know if this answers your questions!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
@alexxhenry That is very cool and very interesting. I bet we could turn that into a plugin. I'm going to have to experiment with this.