–to recreate current feature branch br2 as a clone of br3
The slower method is ” git checkout br3; git branch -d br2; git checkout -b br2″
The slightly faster method is “git reset –hard br3”
–Most git commands accept –help
How to rename a branch on Stash directly?
On your Stash page change base branch to the target branch (say BB) -> click on the “…” dropdown -> choose “Create a branch from here” -> specify new name (say NN) -> delete branch BB.
How to add a tag on Stash directly?
Navigate to the page of your chosen commit (such as this sample page), then find the link on the top right “Tag this commit”
git show your_tag # look into one tag
The Stash page below also helps, provided the tag is published on Stash.
How to add or edit the annotation of a tag on Stash?
… shows all tags, including the commit and the annotation. Choose one you want to edit and go to Actions column click the 3 dots and choose Edit.
Why is `git status` slow in Linux?
It might be due to the networked file system. We’ve found that doing the following might speed it up:
git config --global core.preloadindex True
See stackoverflow for details.
How do I list all branches that change a file?
git log --all --format=%H $FILENAME |
git branch --contains $f; done | sort -u
How do I get rid of obsolete remote branches
First remove it from Stash. Easy and safe to do on Stash web site. Go to the page listing all mod branches. Locate your branch you don’t want. Click on the “…” on the far right, to show the dropdown and find “Delete”. This would complete the deletion on the central repo. Next in your local repo, run
This command would sync up the local repo to match central repo on Stash. The deleted branch will now be deleted locally. Without this step, git branch -a would forever show the obsolete branch.
Remember each local repo or central repo holds a copy of all the branches. Deleting branch123 from one repo doesn’t automatically delete branch123 from another repo. Similarly, adding branch321 to one repo doesn’t automatically add branch321 to another repo.
How to resolve pull request merge conflicts
If possible, we use the Stash interface to merge. The resulting commit message on Develop branch looks like
Sometimes we get a conflict when merging the PR. For example, PR #153 has one file modified in the incoming branch release/0142c. Same file was very recently modified on Develop. Therefore this file had 2 concurrent changes, resulting in a merge conflict. This is what Victor did to resolve it, not necessarily optimal or recommended.
git fetch origin release/0142c
git branch -d develop
git checkout develop # check out latest from Stash
git merge FETCH_HEAD # one file in conflict, to be resolved
git diff origin/develop PyQXLModels_ddl_pycxx.cfg # ensure the diff is exactly what we expect
git add PyQXLModels_ddl_pycxx.cfg
git commit # see the comment message below
git log --simplify-merges # verify
git push origin HEAD # may need special permission to push Develop to Stash
Here’s the commit message I used in the merge commit:
Merge pull request #153 manually from release/0142c to develop
[CFMQUANT-235] resolve minor conflict on one file
Another option for a visual interface for git under Windows is TortoiseGit. This isn’t a GUI, as such, but a shell that sits on top of Windows Explorer. Some people like it for this reason; some people dislike it for this reason.
It gives a convenient way to see the status of your files, and a convenient way (right-clicking) to select most commonly-used git commands (you can of course still use the command line whenever that is more convenient). There is some pain involved in setting up the key for connecting to the server – scroll down to ‘Interface’ and ‘Commands’ below to see if you think the gain is worth the pain.
Git command line is rather rich and powerful, featuring hundreds (possibly thousands:) of commands + sub-commands + combinations of switches to those commands. (https://www.kernel.org/pub/software/scm/git/docs/ lists more than 100 top-level commands). It’s impractical for any GUI tool to emulate the command line. Tortoise provides a good information-radiator tool, that saves you lots of repetitive typing.
Some of the many convenience features
Convenience is where Tortise distinguishes itself from other software tools.
In WinExplorer, Tortise lets you right click any modified file (or multiple files) to commit to your local branch. After the commit, the dialog screen lets you push to the central branch on Stash.
Similarly, if you have a new file to commit, you can right click and add, then commit.
You can also right click and diff with previous version.
Feature: list of all uncommitted files (like git commit –name-status)
TortoiseGit is free, and can be downloaded from http://tortoisegit.org/download/ You’ll need to download the 64 bit version, and then run it (it will prompt for an x account password during the installation). It does try to restart a lot of programs (so make sure you’ve saved everything), but doesn’t require a restart. The default options in the install wizard worked fine for me.
Setting up the Key
For some reason, TortoiseGit only accepts keys in putty key format, so the key that works with Git needs to be converted to this different form (this should be a once-off). An explanation of how is given here: http://develop-for-fun.blogspot.com.au/2013/12/configure-tortoise-git.html (basically you need to download puttygen.exe to convert the format of the key).
Clone the Stash repository (Workspace)
To create a new repository based on the stash repository, you can use Windows Explorer to create a new folder, move into that folder and then right click, and choose “Git Clone…” to bring up a dialog box.
Set the url to ssh://git@….. the directory to where you want it installed. You’ll need to click on “Load Putty Key” and put the address of the putty key saved down from puttygen earlier, which could be any stable folder in your C: drive. Avoid moving this folder.
Once successfully installed, Windows Explorer in folders associated with a workspace will now look something like
- A green circle with a tick: up-to-date. (Victor: based on my earlier TortoiseSVN knowledge, a folder marked green means everything in it is in-sync with remote, a valuable knowledge.)
- A red circle with an exclamation mark: file on disk has been changed and not committed (or for a folder, a file somewhere in that folder – possibly several folders deep – has been changed).
- A blue circle with a question mark: “external” ie have not been added to the list of committed files
- A yellow triangle with an exclamation mark: “conflicted” ie the equivalent of “overlap” in AccuRev
A full list of icons is given at https://tortoisegit.org/docs/tortoisegit/tgit-dug.html#tgit-dug-general-dia-icons
Right clicking on a file or folder brings up a menu of git commands. Right clicking at the top of the directory tree means you can commit all changes, or click on merge to bring up a GUI interface to merge everything.
The full manual can be found at https://tortoisegit.org/docs/tortoisegit/
If you are using a workspace that you set up outside of TortoiseGit (e.g. via the command line), then before you push to, or pull from, the server, you will need to point TortoiseGit to the putty key, by selecting TortoiseGit->Settings, then under “Git”, select “Remote”, then click on “origin” in the “Remote” box, and then set Putty Key.
Enable icons in Win Explorer
Victor had to fix his registry to get Windows Explorer to show the (nice little) icons. In addition to http://martinbuberl.com/blog/tortoisegit-icons-not-showing-workaround/ , he had to kill all Explorer.exe processes in taskmgr before relaunching Explorer.
Explorer “overlay” (technical jargon) is no mature and stable technology. Victor estimates a few times a year the icons would disappear on (subset of) the version-controlled files, often for no obvious reason, and then reappear at a random time. In spite of frequent disappointments, many users love these little icons.