GIT Commands - dennisholee/notes GitHub Wiki

New existing project setup

  1. Initialize an existing project: git init
  2. Register new remote repository: git remote add origin {GIT URL}

Update local repo

  • Fetch and update local repo: git pull origin master
  • Missing tracking information warning
git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

Specify the remote repository and branch i.e. 'origin' and 'master' git pull origin master https://stackoverflow.com/questions/32056324/there-is-no-tracking-information-for-the-current-branch

Commit to remote repo

  1. Add new files git add .
  2. Commit git commit -m '{message}
  3. Push to remote repo git push origin master

Clone remote repo to local

  1. Clone repo git clone {remote Git repo URL}

Resolve Conflict and Accept Remote Changes

$ git push origin master
To https://github.com/{username}/{repo_name}.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/{username}/{repo_name}.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  1. Pull changes git pull origin master where 'origin' it the remote server tag and 'master' it the branch
  2. Checkout the conflicting file from remote server git checkout --theirs {path_to_file}
  3. Add changes git add {path_to_file}
  4. Commit changes git commit -m 'Resolve conflict'
  5. Push changes git push origin master
⚠️ **GitHub.com Fallback** ⚠️