I’m probably doing something wrong. Scenario: 3 computers: server, laptop and firewalled machine, no internet connection.
There’s a git repo on the server which I want to work on on the firewalled machine, in the end transferring changes made there back to the server.
What I’m doing now fails big time, it goes like this: I use the laptop, tar and a USB stick as transfer agents, a bit like this
laptop$ git clone http//server/.../project.git
laptop$ tar cvzf project.tar.gz project
then move the tar via USB to the firewalled machine, where I do:
fwm$ tar xvzf project.tar.gz
fwm$ cd project
fwm$ git branch -a
* master
remotes/origin/x1
remotes/origin/x2
So far, so good. But if I now want to checkout a certain branch (say, “x1”), I get the following message:
fwm$ git co x1
error: pathspec 'x1' did not match any file(s) known to git.
I can try to force my way via a full path, but that seems shaky, too:
fwm$ git co remotes/origin/x1
Note: moving to 'remotes/origin/x1' which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
git checkout -b <new_branch_name>
I say “shaky”, because
fwm$ git status
# Not currently on any branch.
nothing to commit (working directory clean)
What am I doing wrong and what would be the correct way in this scenario?
You’re not doing anything wrong you just haven’t created any local branches yet. All branches of the form
<remote-name>/<branch-name>are remote branches and are supposed to only ever reflect some current or previous state of that branch on that remote, in your caseorigin/x1. Because of this you cannot make commits to these branches (if you did then they would no longer reflect a state of that branch on the remote at some point in the past) so git just doesn’t allow you to actually checkout those branches. Instead of puts you in a state known as a headless branch which you can commit to but if you switch branches your changes will be lost since you don’t have a branch name to reference (you can look up these commits in the reflog though).All you really have to do is create a local branch to work on after you untar the git repository, but this may be a good use case for git bundle