git add remote branch
GitGit Problem Overview
I want to add a remote, and a branch of that remote.
I did git remote add <newname> <url>
, then I did git fetch --all
but git branch -a
is not showing any branch of the remote. My .git/config is showing the added remote.
Can anyone please help me out?
Git Solutions
Solution 1 - Git
I am not sure if you are trying to create a remote branch from a local branch or vice versa, so I've outlined both scenarios as well as provided information on merging the remote and local branches.
Creating a remote called "github":
git remote add github git://github.com/jdoe/coolapp.git
git fetch github
List all remote branches:
git branch -r
github/gh-pages
github/master
github/next
github/pu
Create a new local branch (test) from a github's remote branch (pu):
git branch test github/pu
git checkout test
Merge changes from github's remote branch (pu) with local branch (test):
git fetch github
git checkout test
git merge github/pu
Update github's remote branch (pu) from a local branch (test):
git push github test:pu
Creating a new branch on a remote uses the same syntax as updating a remote branch. For example, create new remote branch (beta) on github from local branch (test):
git push github test:beta
Delete remote branch (pu) from github:
git push github :pu
Solution 2 - Git
You can check if you got your remote setup right and have the proper permissions with
git ls-remote origin
if you called your remote "origin". If you get an error you probably don't have your security set up correctly such as uploading your public key to github for example. If things are setup correctly, you will get a list of the remote references. Now
git fetch origin
will work barring any other issues like an unplugged network cable.
Once you have that done, you can get any branch you want that the above command listed with
git checkout some-branch
this will create a local branch of the same name as the remote branch and check it out.
Solution 3 - Git
I tested what @Samy Dindane suggested in the comment on the OP.
I believe it works, try
git fetch <remote_name> <remote_branch>:<local_branch>
git checkout <local_branch>
Here's an example for a fictitious remote repository named foo
with a branch named bar
where I create a local branch bar
tracking the remote:
git fetch foo bar:bar
git checkout bar
Solution 4 - Git
Here is the complete process to create a local repo and push the changes to new remote branch
- Creating local repository:-
Initially user may have created the local git repository.
$ git init
:- This will make the local folder as Git repository,
-
Link the remote branch:-
Now challenge is associate the local git repository with remote master branch.
$ git remote add RepoName RepoURL
usage: git remote add [
- Test the Remote
$ git remote show
--->Display the remote name
$ git remote -v
--->Display the remote branches
- Now Push to remote
$git add .
----> Add all the files and folder as git staged'
$git commit -m "Your Commit Message"
- - - >Commit the message
$git push
- - - - >Push the changes to the upstream
Solution 5 - Git
You can probably just do..
git checkout branch_name
If the remote branch exists on origin then git will track it if it has the same name.
Solution 6 - Git
If you created a local branch named A and you have a remote branch named B and you want remote branch B to track the changes of local branch A
do the following on your command line or terminal
git branch --set-upstream-to=origin/B A
This will setup upstream of your local branch A to remote branch B
then run
git pull
to pull the changes from B
then run
git push
to push the changes to B
Solution 7 - Git
In my case, I used the following commands to make it work
git fetch origin
git remote add <your_branch> <your_url>
git checkout <your_branch>