From 5c83237c707da85e7e3cba53ec5fe7551a39cdd2 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Mon, 25 Jan 2021 18:02:38 -0600 Subject: [PATCH] Add Create A New Branch With Git Switch as a git til --- README.md | 3 ++- git/create-a-new-branch-with-git-switch.md | 27 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 git/create-a-new-branch-with-git-switch.md diff --git a/README.md b/README.md index 6630c81..7d60cd7 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_1024 TILs and counting..._ +_1025 TILs and counting..._ --- @@ -226,6 +226,7 @@ _1024 TILs and counting..._ - [Clone A Repo Locally From .git](git/clone-a-repo-locally-from-git.md) - [Configure Global gitignore File](git/configure-global-gitignore-file.md) - [Configuring The Pager](git/configuring-the-pager.md) +- [Create A New Branch With Git Switch](git/create-a-new-branch-with-git-switch.md) - [Delete All Untracked Files](git/delete-all-untracked-files.md) - [Determine The Hash Id For A Blob](git/determine-the-hash-id-for-a-blob.md) - [Diffing With Patience](git/diffing-with-patience.md) diff --git a/git/create-a-new-branch-with-git-switch.md b/git/create-a-new-branch-with-git-switch.md new file mode 100644 index 0000000..466d0f2 --- /dev/null +++ b/git/create-a-new-branch-with-git-switch.md @@ -0,0 +1,27 @@ +# Create A New Branch With Git Switch + +As of [Git 2.23](https://www.infoq.com/news/2019/08/git-2-23-switch-restore/), +there is a new command in town for change and creating branches -- +`git-switch`. + +As a git user, you may be used to using `git checkout -b my_branch` to create +and switch to a new branch called `my_branch`. The `git-checkout` command can +do that and a lot more. In order to reduce some confusion and create a more +explicit command for this kind of action. That's what brought about +`git-switch`. + +Create and change to a new branch with `git-switch` and the `-c` flag: + +```bash +$ git switch -c my_new_branch +``` + +The `-c` flag is short for `--create` and the docs describe it as "a convenient +shortcut for:" + +```bash +$ git branch +$ git switch +``` + +See `man git-switch` for more details.