Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git checkout <latest branch you were working on> command

Tags:

git

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.

like image 983
Medeiros Avatar asked Apr 17 '14 14:04

Medeiros


People also ask

Does git checkout checkout from current branch?

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.

How do I get the latest commit?

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.

How do I go back to the last commit in checkout?

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.

How do I switch from Git checkout to branch?

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>.

What can we do with Git checkout?

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.

How to make a new branch of a git repository?

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.

What is the difference between GIT checkout-B and head?

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


1 Answers

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.

like image 191
Bucket Avatar answered Sep 29 '22 14:09

Bucket