git: how to switch between branches?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

git: how to switch between branches?

Markus Neteler
Hi,

being a kind of git newbie, I'm struggly with switching between the
different release branches (and master).

Starting from a clean state (nothing downloaded yet), it this correct:

## 0. getting the code: fork in GH, then
# git clone [hidden email]:your_GH_account/grass.git
# git remote ...

Now I want the each release branch in a separate directory (!) as I
keep the compiled binaries and run GRASS directly from there.

# make a local copy of the freshly cloned source code (example: relbranch76(:
cp -rp grass grass76_branch
cd grass76_branch/

## 1. preparation: check if the local branch-copy of the remote branch exists
git branch -a

# if yes:
#   nothing to do, continue below
# if not:
#   create a new local branch that tracks a remote branch
git checkout --track upstream/releasebranch_7_6
## ?? or
##  git checkout --track remotes/upstream/releasebranch_7_6

# check
git branch -a

## 2. subsequently, switching between master and branch

# switch to branch, e.g.
git checkout upstream/releasebranch_7_6

# back to master
git checkout master

Please suggest, at non-git-expert level :-)

Markus
_______________________________________________
grass-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/grass-dev
Reply | Threaded
Open this post in threaded view
|

Re: git: how to switch between branches?

Michael Barton

____________________
C. Michael Barton
Director, Center for Social Dynamics & Complexity 
Professor of Anthropology, School of Human Evolution & Social Change
Head, Graduate Faculty in Complex Adaptive Systems Science
Arizona State University

Currently Senior Research Fellow, Institute for Advanced Sustainability Studies
Potsdam, Deutchland

voice:  480-965-6262 (SHESC), 480-965-8130/727-9746 (CSDC)
fax: 480-965-7671 (SHESC),  480-727-0709 (CSDC)
www: http://www.public.asu.edu/~cmbartonhttp://csdc.asu.edu






I have similar questions.

Related to this, when we set up our MedLanD project Git repository, we also had some colleagues suggest using Git's forking to deal with collaborative development. But in the end, we decided to follow more of the  previous GRASS SVN approach. It relies more on good practice among developers, but it is easier to remember how to carry out the good practices. 

Michael

On May 20, 2019, at 3:00 AM, [hidden email] wrote:

Date: Sun, 19 May 2019 19:27:34 +0200
From: Markus Neteler <[hidden email]>
To: GRASS developers list <[hidden email]>
Subject: [GRASS-dev] git: how to switch between branches?
Message-ID:
<[hidden email]>
Content-Type: text/plain; charset="UTF-8"

Hi,

being a kind of git newbie, I'm struggly with switching between the
different release branches (and master).

Starting from a clean state (nothing downloaded yet), it this correct:

## 0. getting the code: fork in GH, then
# git clone [hidden email]:your_GH_account/grass.git
# git remote ...

Now I want the each release branch in a separate directory (!) as I
keep the compiled binaries and run GRASS directly from there.

# make a local copy of the freshly cloned source code (example: relbranch76(:
cp -rp grass grass76_branch
cd grass76_branch/

## 1. preparation: check if the local branch-copy of the remote branch exists
git branch -a

# if yes:
#   nothing to do, continue below
# if not:
#   create a new local branch that tracks a remote branch
git checkout --track upstream/releasebranch_7_6
## ?? or
##  git checkout --track remotes/upstream/releasebranch_7_6

# check
git branch -a

## 2. subsequently, switching between master and branch

# switch to branch, e.g.
git checkout upstream/releasebranch_7_6

# back to master
git checkout master

Please suggest, at non-git-expert level :-)

Markus


_______________________________________________
grass-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/grass-dev
Reply | Threaded
Open this post in threaded view
|

Re: git: how to switch between branches?

Michael Barton
In reply to this post by Markus Neteler
Markus and others,

I've looked at this a little now, and here is a possible workflow. For Git sophisticates, I realize that this negates to some extent the lightweight flexibility of the Git approach to versioning. And of course, not everyone has to do this. But to create separate source distributions in different directories locally, so that devs who want to can continue with their current workflow (at least for awhile), you should be able to do the following (example from RB7.4)

CMB-MacBook-Pro:grass_source cmbarton$ mkdir releasebranch_7_4
CMB-MacBook-Pro:grass_source cmbarton$ cd releasebranch_7_4
CMB-MacBook-Pro:releasebranch_7_4 cmbarton$ git clone https://github.com/OSGeo/grass.git
Cloning into 'grass'...
remote: Enumerating objects: 131, done.
remote: Counting objects: 100% (131/131), done.
remote: Compressing objects: 100% (113/113), done.
remote: Total 228899 (delta 31), reused 39 (delta 15), pack-reused 228768
Receiving objects: 100% (228899/228899), 232.04 MiB | 549.00 KiB/s, done.
Resolving deltas: 100% (169949/169949), done.
Checking out files: 100% (7355/7355), done.
CMB-MacBook-Pro:releasebranch_7_4 cmbarton$ cd grass
CMB-MacBook-Pro:grass cmbarton$ git checkout releasebranch_7_4
Branch 'releasebranch_7_4' set up to track remote branch 'releasebranch_7_4' from 'origin'.
Switched to a new branch 'releasebranch_7_4'

This will give you source files from RB7.4. 

Note a couple of other alternatives:

1. You can just clone GRASS once and do a checkout to each branch you want to work on at any time. Git will then replace all files that differ in that branch from master. Not much in 7.6, many more in 7.2

2. You could have one master GRASS directory and one 'branch' directory in which you use checkout for each branch other than master you want to work in when you are in the branch directory. 

Git is very flexible in this regard AFAICT. Most Git tutorials I've seen discuss method 1 above, with discussions of additional forks and merging of branches, assuming that the ultimate goal is to deploy all releases from the master branch. GRASS does not follow this kind of assumed 'normal' work flow. We are working on 2-3 different branch releases simultaneously. 

Of course Git offers the opportunity to begin to rethink the overall GRASS workflow. But we might want to make these transitions in stages to keep everyone on board and limit confusion (e.g., get all up to speed on using Git commands to get the source code and commit revisions more or less the way we do now, and then work out new common workflows for doing these activities). Git's flexibility means that we can make these changes as incrementally or as quickly as works for the community. 

Michael



____________________
C. Michael Barton
Director, Center for Social Dynamics & Complexity 
Professor of Anthropology, School of Human Evolution & Social Change
Head, Graduate Faculty in Complex Adaptive Systems Science
Arizona State University

Currently Senior Research Fellow, Institute for Advanced Sustainability Studies
Potsdam, Deutchland

voice:  480-965-6262 (SHESC), 480-965-8130/727-9746 (CSDC)
fax: 480-965-7671 (SHESC),  480-727-0709 (CSDC)
www: http://www.public.asu.edu/~cmbartonhttp://csdc.asu.edu















On May 20, 2019, at 3:00 AM, [hidden email] wrote:

Message: 2
Date: Sun, 19 May 2019 19:27:34 +0200
From: Markus Neteler <[hidden email]>
To: GRASS developers list <[hidden email]>
Subject: [GRASS-dev] git: how to switch between branches?
Message-ID:
<[hidden email]>
Content-Type: text/plain; charset="UTF-8"

Hi,

being a kind of git newbie, I'm struggly with switching between the
different release branches (and master).

Starting from a clean state (nothing downloaded yet), it this correct:

## 0. getting the code: fork in GH, then
# git clone [hidden email]:your_GH_account/grass.git
# git remote ...

Now I want the each release branch in a separate directory (!) as I
keep the compiled binaries and run GRASS directly from there.

# make a local copy of the freshly cloned source code (example: relbranch76(:
cp -rp grass grass76_branch
cd grass76_branch/

## 1. preparation: check if the local branch-copy of the remote branch exists
git branch -a

# if yes:
#   nothing to do, continue below
# if not:
#   create a new local branch that tracks a remote branch
git checkout --track upstream/releasebranch_7_6
## ?? or
##  git checkout --track remotes/upstream/releasebranch_7_6

# check
git branch -a

## 2. subsequently, switching between master and branch

# switch to branch, e.g.
git checkout upstream/releasebranch_7_6

# back to master
git checkout master

Please suggest, at non-git-expert level :-)

Markus


_______________________________________________
grass-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/grass-dev
Reply | Threaded
Open this post in threaded view
|

Re: git: how to switch between branches?

Panagiotis Mavrogiorgos
In reply to this post by Markus Neteler
Hello Markus

I don't have real-world experience with this, but I am not sure if changing branches and
distcleaning/recompiling is the most convenient workflow. I think I would prefer to have
multiple local repositories with different branches checked out. Thankfully git makes it
rather easy to have this.  E.g.:

1. You create two root directories. One for Python2 and one for Python3:

    mkdir /home/user/git/grass-p{2,3}

2. Create a virtualenv inside grass-p2 and grass-p3. E.g.:

    cd /home/user/git/grass-p2
    virtualenv -p python2 venv

    cd /home/user/git/grass-p2
    python3 -m venv venv

3. Clone the remote GRASS repo and name the local repo `dev`. You will only do this for `grass-p3`:

    cd /home/user/git/grass-p3
    git clone https://github.com/neteler/grass dev

5. For python 2 and for each release branch you will make a local git clone. This way
   you won't be wasting disk space. Read more about this
   [here](https://stackoverflow.com/questions/7187088/git-how-to-create-local-repo-with-symbolic-links-to-the-git-main-repo).

    cd /home/user/git/grass-p2
    git clone ../grass-p3/dev dev
    git clone ../grass-p3/dev r72
    git clone ../grass-p3/dev r74
    git clone ../grass-p3/dev r76

6. The dir structure should look like this:

    $ tree grass*

    grass-p2
    ├── dev
    ├── r72
    ├── r74
    ├── r76
    └── venv
    grass-p3
    ├── dev
    └── venv

7. On each release clone you need to checkout the respective branch:

    cd /home/user/git/grass-p2/r72 && git checkout releasebranch_7_2
    cd /home/user/git/grass-p2/r74 && git checkout releasebranch_7_4
    cd /home/user/git/grass-p2/r76 && git checkout releasebranch_7_6

7. Each directory is a full blown git repo. It is only by convention that 7.6 backports
   will happen in `r76` etc.  If you want to directly pull/push from/to github from the release
   directories, you will probably need to setup remotes. Regardless, setting up remotes
   etc should only be done once.

8. Obviously, when 7.8 gets released, two more directories will need to be added (one
   for python2  and one for python 3).

The benefit of this approach is that at least for trivial backports, you will not need
to recompile everything and, perhaps more importantly, you will not need to recompile
"master" in order to test a fix in 7.2.

all the best,
Panos

PS1. There are other ways to achieve something like this, e.g.
[`--singlebranch`](https://stackoverflow.com/a/1911126/592289) but I don't see much
benefit.

PS2. You can optionally use something like [direnv](https://github.com/direnv/direnv) to
automatically activate the virtualenvs when you cd into the corresponding directory.
This way there is no confusion WRT which python is active. I use this and it works
marvellously.



_______________________________________________
grass-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/grass-dev
Reply | Threaded
Open this post in threaded view
|

Re: git: how to switch between branches?

Markus Neteler
Hi Panos,

thanks so much for writing up this guide which looks very good to me
(and saves disk space; and offers an approach more close to those
freshly coming from SVN)!

Some comments + questions inline:

On Mon, May 20, 2019 at 10:23 AM Panagiotis Mavrogiorgos
<[hidden email]> wrote:

>
> Hello Markus
>
> I don't have real-world experience with this, but I am not sure if changing branches and
> distcleaning/recompiling is the most convenient workflow. I think I would prefer to have
> multiple local repositories with different branches checked out. Thankfully git makes it
> rather easy to have this.  E.g.:
>
> 1. You create two root directories. One for Python2 and one for Python3:
>
>     mkdir /home/user/git/grass-p{2,3}
>
> 2. Create a virtualenv inside grass-p2 and grass-p3. E.g.:
>
>     cd /home/user/git/grass-p2
>     virtualenv -p python2 venv
>
>     cd /home/user/git/grass-p2

... I suppose, it should be
     cd /home/user/git/grass-p3

>     python3 -m venv venv
>
> 3. Clone the remote GRASS repo and name the local repo `dev`. You will only do this for `grass-p3`:
>
>     cd /home/user/git/grass-p3
>     git clone https://github.com/neteler/grass dev
>
> 5. For python 2 and for each release branch you will make a local git clone. This way
>    you won't be wasting disk space. Read more about this
>    [here](https://stackoverflow.com/questions/7187088/git-how-to-create-local-repo-with-symbolic-links-to-the-git-main-repo).
>
>     cd /home/user/git/grass-p2
>     git clone ../grass-p3/dev dev
>     git clone ../grass-p3/dev r72
>     git clone ../grass-p3/dev r74
>     git clone ../grass-p3/dev r76
>
> 6. The dir structure should look like this:
>
>     $ tree grass*
>
>     grass-p2
>     ├── dev
>     ├── r72
>     ├── r74
>     ├── r76
>     └── venv
>     grass-p3
>     ├── dev
>     └── venv

So far, so nice (locally, I used "master" instead of "dev" but that's
cosmetics).

> 7. On each release clone you need to checkout the respective branch:
>
>     cd /home/user/git/grass-p2/r72 && git checkout releasebranch_7_2

Now, here I cannot proceed:

cd $REPOPATH/grass-p2/r72 && git checkout releasebranch_7_2
error: pathspec 'releasebranch_7_2' did not match any file(s) known to git

git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

Any ideas?

>     cd /home/user/git/grass-p2/r74 && git checkout releasebranch_7_4
>     cd /home/user/git/grass-p2/r76 && git checkout releasebranch_7_6
>
> 7. Each directory is a full blown git repo. It is only by convention that 7.6 backports
>    will happen in `r76` etc.  If you want to directly pull/push from/to github from the release
>    directories, you will probably need to setup remotes. Regardless, setting up remotes
>    etc should only be done once.

Yes.

> 8. Obviously, when 7.8 gets released, two more directories will need to be added (one
>    for python2  and one for python 3).

(...looking fwd to dropping Python-2 support)

> The benefit of this approach is that at least for trivial backports, you will not need
> to recompile everything and, perhaps more importantly, you will not need to recompile
> "master" in order to test a fix in 7.2.

Yes, that's pretty cool.

> all the best,
> Panos
>
> PS1. There are other ways to achieve something like this, e.g.
> [`--singlebranch`](https://stackoverflow.com/a/1911126/592289) but I don't see much
> benefit.
>
> PS2. You can optionally use something like [direnv](https://github.com/direnv/direnv) to
> automatically activate the virtualenvs when you cd into the corresponding directory.
> This way there is no confusion WRT which python is active. I use this and it works
> marvellously.

Wow, didn't know about that so far. As soon as I get the problem
mentioned above sorted out I'll try.

Best,
Markus
_______________________________________________
grass-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/grass-dev