EzDevInfo.com

git interview questions

Top git frequently asked interview questions

How do I remove local (untracked) files from my current Git branch?

How do you delete untracked local files from your current branch?


Source: (StackOverflow)

Change the URI (URL) for a remote Git repository

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)

Advertisements

Checkout remote Git branch

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)

Clone all remote branches with Git?

I have a master and a development branch, both pushed to GitHub. I've cloned, pulled, and fetched, 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)

Difference between "git add -A" and "git add ."

The command git add [--all|-A] appears to be identical to git add .. Is this correct? If not, how do they differ?


Source: (StackOverflow)

How can I add an empty directory to a Git repository?

How can I add an empty directory (that contains no files) to a Git repository?


Source: (StackOverflow)

Make an existing Git branch track a remote branch?

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)

What are the differences between 'git pull' and 'git fetch'?

What are the differences between git pull and git fetch?


Source: (StackOverflow)

Undo 'git add' before commit

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)

How do I rename the local branch?

I do not want to rename a remote branch, as described in Rename master branch for both local and remote Git repositories.

Instead, I want to use the simplest way to rename a local branch, which is not pushed to a remote branch.


Source: (StackOverflow)

How do you undo the last commit?

I committed the wrong files to Git.

How can I undo this commit?


Source: (StackOverflow)

Move existing, uncommited work to a new branch in Git

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 submodule?

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)

Remove a file from a Git repository without deleting it from the local filesystem

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)

Reset or revert a specific file to a specific revision using Git?

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)