markdown Git工作流程
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Git工作流程相关的知识,希望对你有一定的参考价值。
## Push a new branch to origin (Github)
https://git-scm.com/book/id/v2/Git-Branching-Remote-Branches
1. Checkout to your local branch or create/checkout a new branch
```sh
# example: create/checkout a new branch called 'map'
git checkout -b map
```
2. Push local new-branch to origin(Github) as a remote branch.
_'-u' option sets up the upstream tracking._
```sh
# git push -u <remote-server> <new-branch>
git push -u origin map
```
## Delete remote branch from origin (Github)
https://git-scm.com/book/id/v2/Git-Branching-Remote-Branches
```sh
# git push <remote-server> --delete <branch-name>
git push origin --delete map
# or
# git push <remote-server> :<branch-name>
git push origin :map
```
## Checkout a remote-branch from origin (Github) aka review a pull request
https://git-scm.com/book/id/v2/Git-Branching-Remote-Branches
1. Download all branches
```sh
git checkout master
git fetch
```
2. View all branches
```sh
git branch -a
```
3. Checkout local copy of remote branch
```sh
git checkout <branch-name>
```
OR if there are other remotes (instead of just 'origin')
```sh
# git checkout-b <new-branch-name> <remote/branch-name>
git checkout -b map origin/map # Branch 'map' set up to track remote branch 'map' from origin.
# switched to a new branch 'serverfix'
```
## Rebase on local branch
1. Be sure local master branch has the latest commits (git pull)
```shell
# from your master branch
git checkout master
git pull
```
2. checkout to local feature branch (example: map)
```shell
git checkout map
```
3. bring over missing master commits into the 'map' branch
```sh
git rebase master
```
**Extra: from here we can merge feature branch to local master branch**
```sh
# switch back to master branch
git checkout master
# merge feature branch to master
git merge map
```
## Rebase origin/master to local master branch
1. Checkout to master branch
```sh
git checkout master
```
2. Fetch commits and then rebase
```sh
git fetch
git rebase
```
## Syncing a forked repo
https://help.github.com/articles/syncing-a-fork/
```sh
# First add the upstream repo (the original repo)
git remote add upstream <git-repo>
# Get all the latest commits from upstream to local
git fetch upstream
# After fetching, merge master tracking-branch with local master branch
git checkout master
git merge upstream/master
# Push to YOUR forked repo location
```
## Untrack files that are already committed to history
```sh
# Removes ALL cached files
$ git rm -r --cached .
$ git add .
$ git commit -m "Clean up ignored files"
```
以上是关于markdown Git工作流程的主要内容,如果未能解决你的问题,请参考以下文章