# Git Remote ###### tags:`git` `cheatsheet` ## Create SSH key * ceate key * get public key ``` $ cat ~/.ssh/id_rsa.pub ``` * Gitlab * `Settings` --> `SSH keys` ## Senario ### Add local repo to remote 1. create local repo (`git init`) 2. commit changes 3. create remote repo on GitLab > Push it to GitLab directly to create the new project ``` git push --set-upstream ssh://git@gitlab.com:7622/namespace/nonexistent-project.git master ``` ### Clone from remote 1. create remote repo on GitLab 2. clone repo 3. commit changes 4. push to remote repo ## Operation ### Add remote repository ``` $ git remote add origin <remote url> ``` * show ``` $ git remote -v $ git remote show origin ``` ### Push ``` $ git push origin master $ git push origin master:master $ git push origin master:remote_master ``` > 「把本地的 master 分⽀推上去後, 在 Server 上更新 master 分⽀的進度, 或是如果不 存在該分⽀的話, 就建立⼀個 master 分⽀」 * show upstream ``` $ git branch -vv ``` * set upstream ``` $ git push -u origin master $ git branch -u origin master ``` ``` $ git branch -u origin/develop develop ``` `-u`: set upstream > upstream: 每個分⽀可以設定⼀個「上游」, 它會指向並追蹤(track) 某個分⽀。 把 origin/master 設定為本地 master 分⽀的 upstream。 ### Pull * fetch ``` $ git fetch ``` * pull fetch + merge ``` $ git pull [--rebase|--no-ff] ``` ### Clone * clone ``` $ git clone <url> ``` ### Note * General push step ``` $ git stash $ git pull --rebase $ git push $ git stash pop ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up