Giter Site home page Giter Site logo

git-exercises's Introduction

Git Exercise

The following practical exercises should give you some familiarity with using Git.

Note: The provided command line examples are to remind you of the correct syntax and keywords, and won't necessarily work if you type them in blindly

Other Note: to get help on a particular git command, use git <command> --help

Setup

  1. Install and setup git on your computer (remember to set your name/email)

    $ git config --global user.name "Firstname Lastname"
    $ git config --global user.email "[email protected]"
  2. Create an account (or login) to GitHub at https://github.com

  3. (optional) Generate a ssh-key and add it to your GitHub account (for more information see https://help.github.com/articles/connecting-to-github-with-ssh/)

    $ ssh-keygen -t rsa -C "[email protected]"
    $ cat ~/.ssh/id_rsa.pub
  4. Fork this repository: https://github.com/martinjrobins/exercise

Exercise 1: Making Commits

  1. Clone the forked repository to your computer

    $ git clone <url>
  2. Create and add a new file

    $ git add <file>
  3. Commit the new file

    $ git commit -m "message"
  4. Examine the state of your repo with git status.

    $ git status
  5. Edit and save your new file, then add it to the staging area. Finally make a new commit with the edited file. At all stages use git status to see how your repository changes

    $ git add <file>
    $ git commit -m "message"
  6. Make some more commits and view the log

    $ git log 
  7. Commit everything you have done so far

    $ git commit -a -m "message"
  8. Push the commits to the server

    $ git push

Exercise 2: Branching and Merging

  1. Create a new branch

    $ git checkout -b new_branch
  2. Edit your new file and commit the result

  3. Swap back to the master branch

    $ git checkout master
  4. Merge new_branch to master

    $ git merge new_branch
  5. Now create conflicting commits in new_branch and master and try to merge them. Note the conflict-resolution markers will look something like this.

    <<<<<<< HEAD
    This is the new line in master
    =======
    This is the new line in branch
    >>>>>>> branch
  6. resolve the conflict (i.e. edit the conflict markers to match how you want the file to look like) and commit the result. Use git log to see the resulting commits on the master branch.

Exercise 3: Collaboration

  1. Push the new branch that you created in the previous exercise to your remote repository

    $ git push origin new_branch
  2. Get the person sitting next to you to clone your repository and checkout your new branch.

    $ git checkout --track origin/new_branch
  3. Both of you make commits to the new branch. Have one person push their commits to the remote and the other merge these with their own commits. Swap roles and repeat the process.

  4. Once you are happy with the state of your new branch, merge it onto your master branch and bask in the glow of your new Git skills.

git-exercises's People

Contributors

alexfletcher avatar martinjrobins avatar tmtuanctu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.