Git and Github tutorial

Create local repository

  1. change to working directory
  2. git init: create a new local repositary
  3. git status: see status of the working directory, files cached and files not cached
    issue: Working directory clean,
    1. No changes happen in the existing files;
    2. No new files are added to the working directory
  4. git add 'NameOfAFile': cache the changes in staging
  5. git commit -m 'CommitNote': to commit cached changes

Push to and pull from the remote repository

  1. create remote empty repository on Github website
  2. git remote add origin 'https://------.git': add the remote repository to local commputer. ‘origin’ is your name of the repository
  3. git push origin master: push local commits to branch master of origin
  4. git pull origin master: pull remote commits from branch master of origin, typically you change your file on Github website but not reflected in your local repository

Clone repository and edit locally

  1. git config --global user.name "Your name"
    git config --global user.email "Your email": define the author
  2. git clone 'https://------.git': download remote repository to local computer
  3. git remote add origin 'https://------.git'
  4. git push origin master
  5. git pull origin master

Merge repository with a dupicate one locally

  1. git remote add origin 'original repository'
    git remote add duplicate 'duplicate repository': add remote
  2. git branch graphics: create branch graphics
    git checkout graphics: switch to branch graphics
    git pull keeghan graphics: cache branch graphics of keeghan to local computer
    git checkout master: switch to master
    git merge graphics: merge branch master with branch graphics, conflicts handled beforehand.
  3. Of course you can finish merging in Github interface

Two separete ways of working on Github

  1. Contribute to a repository
    1. Fork a repository under your own account
    2. Pull from and push to remote repository, work locally
    3. Pull request to the original repository
  2. Merge a repository into yours
    1. Create your repository
    2. Pull in a repository
    3. Merge into yours
    4. Push to your remote repository

Reference

  1. The code train tutorial on Git and Github

版权声明:本文为qq_33785671原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。