0

I'm working with several repositories

  • origin : the remote repository

  • back : which is a backup of the repository on my local PC

  • uptreams : repository for later pull request

     git remote -v
     back    /opt/lampp/htdocs/work/repo_backup/webtrees (fetch)
     back    /opt/lampp/htdocs/work/repo_backup/webtrees (push)
     origin  https://github.com/ckl67/webtrees.git (fetch)
     origin  https://github.com/ckl67/webtrees.git (push)
     upstream        https://github.com/fisharebest/webtrees.git (fetch)
     upstream        https://github.com/fisharebest/webtrees.git (push)
    

Locally In my "git directory" I'm working with several branches

  • master
  • work
  • dev

In my "git directory" I'm working in branch "work" because I want not to interfere with the "master" branch

My repository "back" is used to test the software. This "local" repository is used to ftp the (html,php,javascript) code to a local directory for test (Apache,mysql local server)

When I push to repository "back"

     git push back

All my branches will be pushed too By default repository "back" will point to branch "master"

So this means that I cannot test my code. For that I have to go to repository "back",

   checkout work
   "test"
   checkout master

Because, I have seen that it is not possible to "git push back" when on my repository "back", the branch "work" is activated !!

So I'm a bit in a trouble here.

Question 1) It is possible to checkout remotely a branch ?

From my "git directory" to checkout branch "work" of my repository "back" ? So principle would be from my "git directory"

 git push back
  --> checkout to "work" in repository "back
 * perform test --> ftp to my local directory in order to test
  --> checkout back to "master" in repository "back
 git push back :: to update all branches (master/work/dev)

Solution 2) It is possible to link git directory/work --> back/master Meaning, when I "git push back", back/work will be updated I have tested

  git branch --set-upstream-to=back/master work

But it didn't work

  git branch --set-upstream-to=back/master work
  The 'work' branch is set to follow the remote 'master' branch from 'back'.
  /opt/lampp/htdocs/work/webtrees $ git push back fatal: The upstream branch of your current branch does not match
  with the name of your current branch

Certainly because, in the "repository back" I have

  git clone --depth 1 https://github.com/ckl67/webtrees.git

Thank You

  • About question 1: **yes**. You can checkout a remote branch.... like, say: `git checkout a-remote/a-branch`. That will get you into _detached HEAD_ state and no local branch will be created. – eftshift0 Nov 24 '20 at 17:23
  • Unfortunately, your proposal is not working, can you help please – Christian Klugesherz Nov 25 '20 at 08:59

1 Answers1

0

Running the command on my "git directory", the git result is highlighting that on the repository "back", I'm now pointing to the last commit (Same as in the local work branch)

git checkout back/work
HEAD is now on 34a8a8e small correction in gitignore file for temporary fix of #3479

So, all should be ok !! However on the repository "back"

  VirtualBox:/opt/lampp/htdocs/work/repo_backup/webtrees$ git branch --all
  * master
    work
    remotes/origin/HEAD -> origin/master
    remotes/origin/master

I see that branch master is still checked out !!

Can you explain please, and give the trick ?

Issue seen in visual studio code

  • In the last command there, when you do the checkout, there you are on the _remote_ branch.... well, the revision that the remote branch is pointing to... and you are in detached HEAD.... check with `git status` – eftshift0 Nov 25 '20 at 13:50
  • _plus_, you should add this as additional info to the question by editing it, not have it as an answer. Welcome to SO! – eftshift0 Nov 25 '20 at 13:55
  • Yes you are right, when I run git status in the git directory, I got git status HEAD détachée sur back/master So this means ?? – Christian Klugesherz Nov 25 '20 at 16:47
  • ... So does that mean, that it is not possible to modify the remote branch ?.... Because on repository "back" , I still see that master is checked out – Christian Klugesherz Nov 25 '20 at 16:56
  • You can.... but not by _just_ committing locally. You can commit locally working on detached HEAD or with a local branch and then you can push to the remote branch (if working on detached HEAD you can do `git push the-remote HEAD:the-branch`) – eftshift0 Nov 25 '20 at 17:00
  • I guess my question was not clear. The question was a possibility to modify a branch from my git directory to a remote branch.. – Christian Klugesherz Nov 25 '20 at 17:17
  • You can... just not in a single step. Modifying a remote branch is all about _pushing_ to it. – eftshift0 Nov 25 '20 at 17:28