Lesson 3

Udacity – How to Use Git and GitHub

Lesson 3

Github

Syncing Repositories

  • remote repositories vs local repositories
  • create remote
    • + new repositorie
    • uncheck initialize
  • git remote add (name) (url)
    • if there is only one remote, standard to use origin as name
    • url is at the github repository page
  • git remote -v
    • v stands for verbose and means that git remote will output more information
  • git push (remote) (branch)
    • to send changes to the remote
    • remote is the name of the remote (e.g. origin)
    • branch is the name of the branch to push (e.g. master)
  • git remote set-url origin url
    • will reset the url of the git repository
  • git pull origin master
    • when master has more update than the origin, use this command to pull update into remote.

Forking a Repository

  • Fork link back to the original
  • Fork track how many people forked
  • Branch happen in single repository (e.g. local)
  • Clone is taking a existing repository and create an identical one to it (e.g. local or remote)
  • Fork is like clone but only within Github.
  • Click Fork to fork a repository
    • git clone url
      • to clone the repository into local
      • once clone, the local repository is pointing to github
  • Add collaborator
    • go to setting
    • click collaborator
    • add github username

Merging Remote Changes

  • git fetch remote-name
    • fetch all branches from the given remote
  • git fetch
    • fetches all branches from the origin remote
  • git pull origin master
    • is the same as two steps
    • git fetch master
    • git merge master origin/master
  • git branch -a
    • to see all (-a) branches both local and remote branche
    • without -a will only see local branches
  • git push origin master
    • to push change to github
  • Fast-foward merges (using pull)
    • when you merge two commits, where one is the ancestor of the other. Or one commit is reachable by the other.  (e.g. o <-a <- b, merge b into a)
  • git branch branch-name
    • to create a new branch
  • git checkout branch-name
    • to checkout the new branch
  • git push origin branch-name
    • to push remote to a new branch-name
  • Use pull request to see what changes made in the branch
    • click the branch
    • click pull request
    • edit which fork to compare
    • click create pull request
    • click merge pull request is present if there is no conflict
    • a pull request is more like a merge request
Advertisements