First, clone a remote Git repository and cd into it:
$ git clone git://example.com/myproject
$ cd myproject
Next, look at the local branches in your repository:
$ git branch
* master
But there are other 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 just want to take a quick peek at an upstream branch, you can check it out directly:
$ git checkout origin/experimental
But if you want 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 set up to track remote branch experimental from origin.
Switched to a new branch 'experimental'
Here, "new branch" simply means that the branch is taken from the index and created locally for you. As the previous line tells you, the branch is being set up to track the remote branch, which usually means the origin/branch_name branch.
Now, if you look at your local branches, this is what you'll see:
$ git branch
* experimental
master
You can actually 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 &
You can undo git add
before commit with
git reset <file>
which will remove it from the current index (the "about to be committed" list) without changing anything else.
You can use
git reset
without any file name to unstage all due changes. This can come in handy when there are too many files to be listed one by one in a reasonable amount of time.
In old versions of Git, the above commands are equivalent to git reset HEAD <file>
and git reset HEAD
respectively, and will fail if HEAD
is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch called HEAD
, which is a stupid thing that you shouldn't do). This was changed in Git 1.8.2, though, so in modern versions of Git you can use the commands above even prior to making your first commit:
"git reset" (without options or parameters) used to error out when
you do not have any commits in your history, but it now gives you
an empty index (to match non-existent commit you are not even on).
Documentation: git reset
Best Answer
Option A:
Ergo, for
right here
use:Option B:
Move the
.git
folder, too. Note that the.git
folder is hidden in most graphical file explorers, so be sure to show hidden files.The first line grabs all normal files, the second line grabs dot-files. It is also possibe to do it in one line by enabling dotglob (i.e.
shopt -s dotglob
) but that is probably a bad solution if you are asking the question this answer answers.Better yet:
Keep your working copy somewhere else, and create a symbolic link. Like this:
For your case this would be something like:
Which easily could be changed to test if you wanted it, i.e.:
without moving files around. Added
-fn
in case someone is copying these lines (-f
is force,-n
avoid some often unwanted interactions with already and non-existing links).If you just want it to work, use Option A, if someone else is going to look at what you have done, use Option C.