Is there a command to permit checkout the last branch? Like:
git checkout --recent
or
git checkout --previous
The idea is when you switch branch too often you it's easy to forget the branch you were working before the current one. Also if there's a way to set a alias for this that would be valide.
The "checkout" command can switch the currently active branch - but it can also be used to restore files. The most common use case for "checkout" is when you want to switch to a different branch, making it the new HEAD branch.
If you want to see what's happened recently in your project, you can use git log . This command will output a list of the latest commits in chronological order, with the latest commit first.
If you want to test the previous commit just do git checkout <test commit hash> ; then you can test that last working version of your project. If you want to revert the last commit just do git revert <unwanted commit hash> ; then you can push this new commit, which undid your previous commit.
git checkout <branch>. To prepare for working on <branch>, switch to it by updating the index and the files in the working tree, and by pointing HEAD at the branch. Local modifications to the files in the working tree are kept, so that they can be committed to the <branch>.
We can perform many operations by git checkout command like the switch to a specific branch, create a new branch, checkout a remote branch, and more. The git branch and git checkout commands can be integrated.
To make a new branch git checkout command is used. The command git checkout is used to check out the desired status of your repository, be it any branch or a particular file. It can also be used for switching between existing local branches.
By default, git checkout -b will base the new branch off the current HEAD where HEAD is Git’s way of referring to the current snapshot. 2. Switching Branches
What you're looking for is -
git checkout -
For example, say you're on branch foo
, and there exists a branch bar
.
* foo
bar
Check out bar
> git checkout bar
foo
* bar
Going back to foo
> git checkout -
* foo
bar
The -
"shortcut" also works for the cd
and ls
commands from within a bash terminal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With