How do I add Git submodule to a sub-directory?
2022-02-11
Question I have a Git repo in ~/.janus/ with a bunch of submodules in it. I want to add a submodule in ~/.janus/snipmate-snippets/snippets/, but when I run git submodule add <git@github.com:...> in the snipmate-snippets directory, I get the following error message: You need to run this command from the top level of the working tree. So the question is: How do I add a submodule to the snipmate-snippets directory? Answer You go into ~/.…
Commit only part of a file's changes in Git
2022-02-10
Question When I make changes to a file in Git, how can I commit only some of the changes? For example, how could I commit only 15 lines out of 30 lines that have been changed in a file? Answer You can use: git add --patch <filename> or for short: git add -p <filename> Git will break down your file into what it thinks are sensible "hunks" (portions of the file).…
How to link a folder with an existing Heroku app
2022-02-10
Question I have an existing Rails app on GitHub and deployed on Heroku. I'm trying to set up a new development machine and have cloned the project from my GitHub repository. However, I'm confused as to how to link this folder up to Heroku. Originally, I used the heroku create command, but obviously I don't want to do that this time since it will create another Heroku instance. Answer Heroku links your projects based on the heroku git remote (and a few other options, see the update below).…
How to use git bisect?
2022-02-10
Question I have read some articles saying that git bisect is awesome. However, I can't understand why it's awesome. Could someone please demonstrate with some code sample: How to use it? Is it just like svn blame? Answer The idea behind git bisect is to perform a binary search in the history to find a particular regression. Imagine that you have the following development history: ... --- 0 --- 1 --- 2 --- 3 --- 4* --- 5 --- current You know that your program is not working properly at the current revision, and that it was working at the revision 0.…
Clone only one branch [duplicate]
2022-02-08
Question This question already has answers here: </div> How do I clone a single branch in Git? (27 answers) Closed 7 years ago. I would like to know how I could clone only one branch instead of cloning the whole Git repository. Answer From the announcement Git 1.7.10 (April 2012): git clone learned --single-branch option to limit cloning to a single branch (surprise!); tags that do not point into the history of the branch are not fetched.…
How do I change the default location for Git Bash on Windows?
2022-02-07
Question I am using Git on Windows 7 and access my repositories through Git Bash. How can I change the default location that Git Bash opens in a convenient folder when I start it? It's somewhat time consuming to navigate to htdocs, and then a specific folder. Is there a way to change the configuration file to have it open elsewhere? Or would it be possible to write a .sh file to do this?…
How do you get git to always pull from a specific branch?
2022-02-07
Question I'm not a git master, but I have been working with it for some time now, with several different projects. In each project, I always git clone [repository] and from that point, can always git pull, so long as I don't have outstanding changes, of course. Recently, I had to revert to a previous branch, and did so with git checkout 4f82a29. When I was again ready to pull, I found that I had to set my branch back to master.…