> For the complete documentation index, see [llms.txt](https://i.janardhanpulivarthi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://i.janardhanpulivarthi.com/season-1/faq-git.md).

# FAQ - git

#### How do I undo 'git add' before commit?

`git reset`

.<https://git-scm.com/docs/git-reset#Documentation/git-reset.txt-Undoadd>

#### Reset local repository branch to be just like remote repository HEAD

`git reset HEAD`

.<https://git-scm.com/docs/git-reset#Documentation/git-reset.txt-emgitresetemltmodegtltcommitgt>

#### How do I checkout a remote Git branch

`git fetch j143 <branch-name>`

#### How do I delete a Git branch locally and remotely?

`git branch -d -r origin/branch-name`

.<https://git-scm.com/docs/git-branch#Documentation/git-branch.txt-Deleteanunneededbranch>

#### How to change URI for a remote git repository

`git remote set-url --add <name> <new-url>`

.<https://git-scm.com/docs/git-remote#_synopsis>

#### How do I push a new local branch to a remote git repository and track it?

`git push --set-upstream origin new-local-branch`

#### How do I revert a git repository to previous commit?

`git reset commit-SHA --hard`

#### How can I add empty directory to a git repository?

We cannot add empty directory. But, we need to keep a file `.gitkeep` or `.gitignore` or just `.keep` file with empty contents. For example, `touch .keep` would create a `.keep` file.

.<https://git-scm.com/docs/git-add#Documentation/git-add.txt-ltpathspecgt82308203>

specifying `git add <dir>` would add `dir/file1` and `dir/file2`.

#### Unstage files?

```bash
> git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   install.md
        modified:   MultiLogReg.dml
        new file:   MLogRegTest.java

> git restore --staged MultiLogReg.dml MLogregTest.java

> git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   install.md

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   MultiLogReg.dml

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        MLogregTest.java
        
> git stash

> git commit -m "update only install.md file"
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://i.janardhanpulivarthi.com/season-1/faq-git.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
