Git Command(Section 3)

This section is used to record some problems and solutions. Welcome to ask questions and discuss them.

Q & A

Q1

If I want to abandon changes on a branch like dev and fetch the remote banch of the same name?

1
$ git checkout -B dev

If -B is given, is created if it doesn’t exist; otherwise, it is reset. This is the transactional equivalent of

1
2
$ git branch -f <branch> [<start point>]
$ git checkout <branch>

Q2

when someone build a new branch on remote repository, but I couldn’t find the new-built branch on my remote branches on my computer.

1
$ git fetch -p

The command will fetch remote branches again if the branch has been added, removed or changed.

Q3

You are needed to fix bugs on a new emergency branch on the same remote repository when you develop on the feature branch.
But the feature branch counldn’t be pushed to the remote repository because the develop work is not finished. Now you should
save you work on the feature branch at first.

1
2
3
4
5
6
7
git stash
```
The command saves your local modifications away and reverts the working directory to match the HEAD commit.
And then checkout the fixbug branch and fix bugs. After you completed the work on the fixbug branch and pushed it to the
remote repository, you checkout the origin feature branch and restore the changes you saved.
```bash
git stash apply stash@{0}

Then you could continue your previous work.