2017-04-05 7:42 GMT+02:00 Michael <keybou...@gmail.com>:

> Worktrees, as I understand it, are about letting one repository have two
> working directories with two different checkouts. Historically, git was
> designed on the assumption that one repository supported one checkout/one
> directory tree.
>
> Maybe this is the key insight for you: one (normal; not sure about bare)
> repository per checkout. To switch from one branch to another, you commit
> what you are doing, and then do a clean switch (this is the "stash"
> command), or else when you switch, you are taking whatever diffs you have
> over to the other branch with a hidden merge (NB: you are taking the
> uncommitted diffs, not the files. If you need to move the files, stash
> first, do a clean switch, and then checkout the files from the stash. It
> took me a while to understand that point.)
>

This is much too complicated for a beginner.

Clean switch means to have no changes in your working directory when you
change to another branch (checkout)
Stashing something means clearing (cleaning) your working directory and
keeping the changes somewhere else
Switching branches is something you shouldn't have to be doing all the time.

The worktree command above is then pretty advanced; you create apparently a
second working directory which may complicate things, so don't focus on
that now?

Switching branches while having an unclean directory is typically not
possible.

error: Your local changes to the following files would be overwritten by
checkout:
       file.c
Please, commit your changes or stash them before you can switch branches.
Aborting


> I am now going to make some guesses, because we don't have the full
> information.
>
> I have two directories. The one called bitbucket/source contains the
> cloned repository which was set up by another developer and the other one
> is called bitbucket/sourcecode which contains the same from my localhost so
> some of the files in there have been modified due to code changes. So now
> supposedly I create a branch and add those files from bitbucket/sourecode.
> A ridiculous amount of work. I'm going to be spending 80% of my time on
> overhead now that we have this new source control requirement.
>
>
>
> My guess is this:
>
> 1. You've got an official repository on bitbucket.
> 2. Someone else set up bitbucket/source as that project.
> 3. If you go to "bitbucket/source", and type "git status", it will respond
> "On branch master, nothing to commit".
>
> 4. Over in bitbucket/sourcecode is a directory tree containing a copy of
> your codebase, that has been subjected to modifications by lots of other
> people.
>

Only by himself.

I assume it is also a git repository but he will have to stash his changes
into a different branch and that is perhaps all?

- git stash -u
- git checkout -b newbranch (this is a combined command of git branch and
git checkout)
- git stash pop

That is all you need to do in order to put your changes into a different
branch given that you are already in a git repository.

If your "sourcecode" directory is not a git repository as this person
assumes here, then you can simply clone a git repository of your own, copy
these files (the entire sourcecode tree you have without the git) on TOP of
it and "git status" will at that point show your changes.

I don't see what's the big issue.

Get yourself a git repository, copy your changes into it (regular
filesystem copy), "git stash -u" the changes, checkout to a different
branch (git checkout -b newbranch) and pop the stash again (git stash pop).
Now you can add your changes to the index of that branch in that sense (git
add .) and commit them (git commit -m "Message") (or git commit, and write
a message in the editor).

Now you have your branch with the changes in the branch and committed to
that branch. Remember that you can always stash the changes to the working
directory as compared to the previous commit of the current branch you are
on, which will also ignore everything in .gitignore,

with git stash -u

Always work in your local repository, don't do anything in the repository
of that other developer.

once you have a stash, change to a different branch, and pop it out again.

pop it out part by part with "git checkout -p stash".

parts you pop out get applied to the working tree (directory) and you can
add them to the index (if that is even necessary) and commit them.

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to