git interview questions
Top git frequently asked interview questions
I have a repo (origin) on a USB key that I cloned on my hard drive (local). I moved "origin" to a NAS and successfully tested cloning it from here.
I would like to know if I can change the URI of "origin" in the settings of "local" so it will now pull from the NAS, and not from the USB key.
For now, I can see two solutions:
push everything to the usb-orign, and copy it to the NAS again (implies a lot of work due to new commits to nas-origin);
add a new remote to "local" and delete the old one (I fear I'll break my history).
Source: (StackOverflow)
I am trying to checkout a remote branch:
Somebody pushed a branch called test
with git push origin test
to a shared repository. I can see the branch with git branch -r
. But how can I get this branch?
git checkout test
does nothing
git checkout origin/test
does something, but git branch
says * (no branch)
. I am on no branch?
How do I share branches via a public repository?
Source: (StackOverflow)
I have a master
and a development
branch, both pushed to GitHub. I've clone
d, pull
ed, and fetch
ed, but I remain unable to get anything other than the master
branch back.
I'm sure I'm missing something obvious, but I have read the manual and I'm getting no joy at all.
Source: (StackOverflow)
The command git add [--all|-A]
appears to be identical to git add .
. Is this correct? If not, how do they differ?
Source: (StackOverflow)
I know how to make a new branch that tracks remote branches, but how do I make an existing branch track a remote branch?
I know I can just edit the .git/config
file, but it seems there should be an easier way.
Source: (StackOverflow)
I mistakenly added files using the command:
git add myfile.txt
I have not yet run git commit
. Is there a way to undo this, so these files won't be included in the commit?
Source: (StackOverflow)
I started some work on a new feature and after coding for a bit, I decided this feature should be on its own branch.
How do I move the existing uncommitted changes to a new branch and reset my current one?
I want to reset my current branch while preserving existing work on the new feature.
Source: (StackOverflow)
How do I remove a Git submodule?
By the way, is there a reason I can't simply do
git submodule rm whatever
?
Source: (StackOverflow)
My initial commit contained some log files. I've added *log
to my .gitignore
, and now I want to remove the log files from my repository.
git rm mylogfile.log
will remove a file from the repository, but will also remove it from the local file system.
How can I remove this file from the repo without deleting my local copy of the file?
Source: (StackOverflow)
I have made some changes to a file which has been committed a few times as part of a group of files, but now want to reset/revert the changes on it back to a previous version.
I have done a git log
along with a git diff
to find the revision I need, but just have no idea how to get the file back to its former state in the past.
Source: (StackOverflow)