简体   繁体   中英

How to checkout a remote git branch ? Or to link a remote branch with a different git directory branch?

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

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 ?

在 Visual Studio 代码中看到的问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM