How can I get a list of Git branches that I’ve recently checked out?

Summary: You can use Git’s reflog to show recent movements in order of checkout: git reflog Script: Here’s a script you can download and use via git recent from inside any Git repository: https://gist.github.com/jordan-brough/48e2803c0ffa6dc2e0bd Usage: $ (master) git recent -n 5 1) master 4) deleted-branch 2) stable 5) improve-everything 3) fun Choose a branch: 2 … Read more

Can I use “git checkout –” on two files?

Run the command multiple times git checkout — path/to/file/one git checkout — path/to/file/two Or specify the multiple files in the same line: git checkout — path/to/file/one path/to/file/two You can also specify entire folders which will recurse to all files below them. git checkout — path/to/folder git checkout — . # for the current path

error: pathspec ‘test-branch’ did not match any file(s) known to git

The modern Git should able to detect remote branches and create a local one on checkout. However if you did a shallow clone (e.g. with –depth 1), try the following commands to correct it: git config remote.origin.fetch ‘+refs/heads/*:refs/remotes/origin/*’ git fetch –all and try to checkout out the branch again. Alternatively try to unshallow your clone, … Read more

How do I intentionally detach HEAD in git?

Since git 1.7.5 (April 2011), you can use the git checkout –detach command. (Since Git 2.23 (Q3 2019), you would use git switch –detach) See commit 326696 checkout: introduce –detach synonym for “git checkout foo^{commit}“ For example, one might use this when making a temporary merge to test that two topics work well together. Commit … Read more

Fetch a single tag from remote repository

git fetch origin refs/tags/1.0.0 This fails because it doesn’t write a local reference: it obtains the remote’s refs/tags/1.0.0, and any tag object(s), commits, etc., required to go with it; it drops those into FETCH_HEAD (as all git fetch commands always do); and … that’s it. It never creates reference refs/tags/1.0.0 in your repository, even though … Read more