Chris,

On 4/25/2019 12:07 PM, Christopher Schultz wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Igal,

On 4/25/19 14:03, Igal Sapir wrote:
Chris,

On 4/25/2019 10:32 AM, Christopher Schultz wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256

Igal,

On 4/23/19 12:52, Igal Sapir wrote:
Another thing that I have changed in my workflow based on
Mark's past suggestion, is that I keep a local repo for each
major branch now.
Okay, I have done the following:

1. Fork tomcat master to my own GitHub account
Since you are a committer you don't need to this.  That is useful
though if you want to show a large update so that others can review
it, but you can also do that in a new branch.

2. git clone URL 3. edit/add/commit/push 4. Create a PR

I'm sure I can import the PR into tomcat-master. No problem.

Now, when attempting to keep my fork current, I've always done
something like:

git remote add upstream master-url git checkout master git fetch
upstream

And I'm all up-to-date.

When I did that, I ended up bringing-down the 7.0.x and 8.5.x
branches as well. How can I limit the upstream to just the
master?

Or does my fork have to have everything, but I have to checkout
a single branch? If so, I'm not sure how to do that.
Your fork has the whole git repository, but fortunately git
manages resources much better than Subversion, for example, so it's
not too bad at all.

You can see a list of the local branches and which branch you are
currently on with the command, `git branch`, which will show
something like this:

git branch
7.0.x 8.5.x * master
$ git branch
* master

So it looks like I forked the branch, which was the intent. To get
this down to my local system, I just did a "git clone [my-repo-url]"
and that's what I got.

I'm pretty sure that you have the whole repository with all three branches, but only one local tracking branch (the default master branch).  Try to run `git branch -a` and it should show you all of the branches, including remote ones.

I have set up a new local repo to test (hopefully my new line characters are preserved in fixed font).:

    igal@localhost c:\Temp
    > git clone https://github.com/apache/tomcat
    Cloning into 'tomcat'...
    remote: Enumerating objects: 99, done.
    remote: Counting objects: 100% (99/99), done.
    remote: Compressing objects: 100% (50/50), done.
    remote: Total 342523 (delta 54), reused 75 (delta 40), pack-reused 342424
    Receiving objects: 100% (342523/342523), 88.78 MiB | 7.71 MiB/s, done.
    Resolving deltas: 100% (225766/225766), done.
    Checking out files: 100% (4005/4005), done.

    igal@localhost c:\Temp
    > cd tomcat

This is what you see now:

    igal@localhost c:\Temp\tomcat
    > git branch
    * master

This shows the remote branches as well:

    igal@localhost c:\Temp\tomcat
    > git branch -a
    * master
      remotes/origin/7.0.x
      remotes/origin/8.5.x
      remotes/origin/HEAD -> origin/master
      remotes/origin/master

Checking out a branch that exists remotely but not locally creates a local branch that tracks the remote one:

    igal@localhost c:\Temp\tomcat
    > git checkout 8.5.x
    Checking out files: 100% (1787/1787), done.
*Branch '8.5.x' set up to track remote branch '8.5.x' from 'origin'.*
    Switched to a new branch '8.5.x'

Listing the branches now shows the new local branch:

    igal@localhost c:\Temp\tomcat
    > git branch -a
    * 8.5.x
      master
      remotes/origin/7.0.x
      remotes/origin/8.5.x
      remotes/origin/HEAD -> origin/master
      remotes/origin/master

The `*` denotes the current branch, so I am on the master branch.
Switching to the 8.5.x branch with `git checkout 8.5.x`

git checkout 8.5.x
Checking out files: 100% (1787/1787), done. Switched to branch
'8.5.x' Your branch is up to date with 'origin/8.5.x'.

And then running again `git branch` will show the * next to 8.5.x:

git branch
7.0.x * 8.5.x master

In some projects it's easy to maintain a single repository and
switch between branches, but I find the differences between 7.0.x
and master to be so major that I chose to follow Mark's method and
keep separate local copies where the IDE settings do not get
mangled up each time I switch branches.
Sounds good. What is Mark's Method™? Is it documented anywhere?

Most git users, as well as myself until recently, use one repository and switch between branches as needed.  You need to work on 7.0.x, you do `git checkout 7.0.x`, work on it, commit and push your changes, and then check out another branch to work on.

The changes between 7.0.x and 8.5.x are so vast that switching between 7.0.x and the other two branches messed up my IDE, so what I refer to as Mark's Method™ is to have 3 local directories/repos (tomcat, tomcat-8.5.x, tomcat-7.0.x), one for each main branch. Each directory/repo stays on its own branch, and the branches are created .  When I want to synchronize them, I do a push in one directory, and then a pull in the other.  So for example let's say that I pushed something on 7.0.x:

    /workspace/src/tomcat-7.0.x$ git push

The next time I work on master or 8.5.x I first do `git pull` to bring it up to date.

    /workspace/src/tomcat$ git pull

That way each directory has its own IDE settings, and they do not get messed up when I work on different branches.

Also, because I create the local tracking branches with `git checkout <branchname>` from the remote branches, they are already set up to track the respective remotes.

Hope this makes sense,

Igal

Reply via email to