Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use git switch instead of git checkout or git branch #7216

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ can be contributed to scikit-image.

* Pull the latest changes from upstream::

git checkout main
git switch main
git pull upstream main

* Create a branch for the feature you want to work on. Use a sensible name,
such as 'transform-speedups'::

git checkout -b transform-speedups
git switch -c transform-speedups

* Commit locally as you progress (with ``git add`` and ``git commit``).
Please write `good commit messages
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ source:

.. code-block:: sh

git checkout main
git switch main
git pull upstream main

And you likely want to create a feature branch from there.
Expand Down
18 changes: 9 additions & 9 deletions doc/source/gitwash/development_workflow.rst
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think gitwash is a git submodule. It seems possible to commit changes here but we might want to upstream these changes as well or instead? Thoughts?

Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ what the changes in the branch are for. For example ``add-ability-to-fly``, or
# Update the mirror of trunk
git fetch upstream
# Make new feature branch starting at current trunk
git branch my-new-feature upstream/main
git checkout my-new-feature
git branch cool-new-feature upstream/main
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is no longer needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd replace both lines (this one and the one below) with the equivalent command

git switch -c cool-new-feature upstream/main

from the man page

git switch [<options>] (-c|-C) <new-branch> [<start-point>]

Note: that the -n option in the line below doesn't exist.

git switch -n cool-new-feature

Generally, you will want to keep your feature branches on your public github_
fork of `scikit-image`_. To do this, you `git push`_ this new branch up to your
github repo. Generally (if you followed the instructions in these pages, and by
default), git will have a link to your github repo, called ``origin``. You push
up to your own repo on github with::

git push origin my-new-feature
git push origin cool-new-feature

In git >= 1.7 you can ensure that the link is correctly set by using the
``--set-upstream`` option::

git push --set-upstream origin my-new-feature
git push --set-upstream origin cool-new-feature

From now on git will know that ``my-new-feature`` is related to the
``my-new-feature`` branch in the github repo.
From now on git will know that ``cool-new-feature`` is related to the
``cool-new-feature`` branch in the github repo.

.. _edit-flow:

Expand All @@ -121,7 +121,7 @@ In more detail
# On branch ny-new-feature
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# (use "git switch -- <file>..." to discard changes in working directory)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I am sorry. @stefanv Should I use "git switch --detach " instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is output generated by git, so should be left alone. Or, best to simulate it with a recent version of git to see what the output looks like now that branch/restore are available.

#
# modified: README
#
Expand Down Expand Up @@ -176,7 +176,7 @@ Delete a branch on github

::

git checkout main
git switch main
# delete branch locally
git branch -D my-unwanted-branch
# delete branch on github
Expand Down Expand Up @@ -271,7 +271,7 @@ To do a rebase on trunk::
# Update the mirror of trunk
git fetch upstream
# go to the feature branch
git checkout cool-feature
git switch -c cool-feature --track someone/cool-feature
# make a backup in case you mess up
git branch tmp cool-feature
# rebase cool-feature onto trunk
Expand Down
2 changes: 1 addition & 1 deletion doc/source/gitwash/git_resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ online manual pages for some common commands:

* `git add`_
* `git branch`_
* `git checkout`_
* `git switch`_
* `git clone`_
* `git commit`_
* `git config`_
Expand Down
2 changes: 1 addition & 1 deletion doc/source/gitwash/maintainer_workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ looking at someone's changes like this::
git remote add someone https://github.com/someone/scikit-image.git
git fetch someone
git branch cool-feature --track someone/cool-feature
git checkout cool-feature
git switch cool-feature
anamfatima1304 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be combined with the branch command above, as before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank You @stefanv Should I just remove line number 35 then?


So now you are on the branch with the changes to be incorporated upstream. The
rest of this section assumes you are on this branch.
Expand Down
10 changes: 4 additions & 6 deletions doc/source/gitwash/patching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ Overview
git clone https://github.com/scikit-image/scikit-image.git
# make a branch for your patching
cd scikit-image
git branch the-fix-im-thinking-of
git checkout the-fix-im-thinking-of
git switch -c the-fix-im-thinking-of
# hack, hack, hack
# Tell git about any new files you've made
git add somewhere/tests/test_my_bug.py
Expand Down Expand Up @@ -67,8 +66,7 @@ In detail
access to an unmodified copy of the code in the main
branch::

git branch the-fix-im-thinking-of
git checkout the-fix-im-thinking-of
git switch -c the-fix-im-thinking-of

#. Do some edits, and commit them as you go::

Expand Down Expand Up @@ -105,7 +103,7 @@ In detail
When you are done, to switch back to the main copy of the
code, just return to the ``main`` branch::

git checkout main
git switch main

Moving from patching to development
===================================
Expand All @@ -119,7 +117,7 @@ Fork the `scikit-image`_ repository on github |emdash| :ref:`forking`.
Then::

# checkout and refresh main branch from main repo
git checkout main
git switch main
git pull origin main
# rename pointer to main repository to 'upstream'
git remote rename origin upstream
Expand Down