Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I have a master and a development branch, both pushed to GitHub. I've cloned, pulled, and fetched, but I remain unable to get anything other than the master branch back.

I'm sure I'm missing something obvious, but I have read the manual and I'm getting no joy at all.

1 Answer

0 votes
by (62.9k points)

The first step you'd do is, clone a remote git repository and cd into it:

$ git clone git://example.com/myproject

$ cd myproject

Next, verify the local branches in your repository:

$ git branch

* master

But there are different branches hiding in your repository. You can see these using the -a flag:

$ git branch -a

* master

remotes/origin/HEAD

remotes/origin/master

remotes/origin/v1.0-stable

remotes/origin/experimental

If you simply need to take a quick peek at an upstream branch, you can check it out directly:

$ git checkout origin/experimental

But if you wish to work on that branch, you'll need to create a local tracking branch which is done automatically by:

$ git checkout experimental

and you will see

Branch experimental started to track remote branch experimental from the origin.

Switched to a new branch 'experimental'

What it really means is that the branch is taken from the index and created locally for you. The previous line is basically more informative because it tells you that the branch is being set up to track the remote branch, which usually means the origin/branch_name branch.

Now, if you look into your native branches, this is what you'll see:

$ git branch

* experimental

master

You can truly track more than one remote repository using git remote.

$ git remote add win32 git://example.com/users/joe/myproject-win32-port

$ git branch -a

* master

remotes/origin/HEAD

remotes/origin/master

remotes/origin/v1.0-stable

remotes/origin/experimental

remotes/win32/master

remotes/win32/new-widgets

At this point, things are getting pretty crazy, so run gitk to see what's going on:

$ gitk --all &

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...