Can you delete multiple branches in one command with Git?
2022-09-20
Question I'd like to clean up my local repository, which has a ton of old branches: for example 3.2, 3.2.1, 3.2.2, etc. I was hoping for a sneaky way to remove a lot of them at once. Since they mostly follow a dot release convention, I thought maybe there was a shortcut to say: git branch -D 3.2.* and kill all 3.2.x branches. I tried that command and it, of course, didn't work.…
git switch branch without discarding local changes
2022-09-20
Question Alright, lets say one day we make happen to make a bunch of modifications and when we go to commit them we notice we were working on the wrong branch. How can we force git to switch branches without discarding local changes. I'm probably going to go about this in a naive way while I wait a reply, but I would like to know if theres a correct procedure as I'd be lying if I said this hasn't happened to me before.…
Switch branch and ignore any changes without committing
2022-09-20
Question I was working on a git branch and was ready to commit my changes, so I made a commit with a useful commit message. I then absentmindedly made minor changes to the code that are not worth keeping. I now want to change branches, but git gives me, error: You have local changes to "X"; cannot switch branches. Can I change branches without committing? If so, how can I set this up?…
git cherry-pick says "...38c74d is a merge but no -m option was given"
2022-09-19
Question I made some changes in my master branch and want to bring those upstream. When I cherry-pick the following commits. However, I get stuck on fd9f578 where git says: $ git cherry-pick fd9f578 fatal: Commit fd9f57850f6b94b7906e5bbe51a0d75bf638c74d is a merge but no -m option was given. What is git trying to tell me and is cherry-pick the right thing to be using here? The master branch does include changes to files which have been modified in the upstream branch, so I'm sure there will be some merge conflicts but those aren't too bad to straighten out.…
How do I show the changes which have been staged?
2022-09-19
Question I staged a few changes to be committed. How do I see the diffs of all files which are staged for the next commit? Is there a handy one-liner for this? git status only shows names of files which are staged, but I want to see the actual diffs. The git-diff(1) man page says: git diff [--options] [--] […] This form is to view the changes you made relative to the index (staging area for the next commit).…
Message 'src refspec master does not match any' when pushing commits in Git
2022-09-19
Question I clone my repository with: git clone ssh://xxxxx/xx.git But after I change some files and add and commit them, I want to push them to the server: git add xxx.php git commit -m "TEST" git push origin master But the error I get back is: error: src refspec master does not match any. error: failed to push some refs to 'ssh://xxxxx.com/project.git' Answer Maybe you just need to commit. I ran into this when I did:…
What's the difference between HEAD, working tree and index, in Git?
2022-09-19
Question Can someone tell me the difference between HEAD, working tree and index, in Git? From what I understand, they are all names for different branches. Is my assumption correct? I found this: A single git repository can track an arbitrary number of branches, but your working tree is associated with just one of them (the "current" or "checked out" branch), and HEAD points to that branch. Does this mean that HEAD and working tree are always the same?…