Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Version Controlling using Git - The Basics

Version Controlling using Git - The Basics

Nishan Chathuranga

May 17, 2020
Tweet

More Decks by Nishan Chathuranga

Other Decks in Education

Transcript

  1. Version control systems are a category of software tools that

    help a software team manage changes to source code over time. Version control software keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members. What is version control
  2. By far, the most widely used modern version control system

    in the world today is Git. Git is a mature, actively maintained open source project originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel. What is Git
  3. For us to share and work collaboratively with other developers,

    we require access to a Git-based hosted service. • GitHub • Bitbucket • GitLab • Microsoft Visual Studio Team Services Git can be accessed and managed using command line tools. There are graphical User Interface (GUI) clients such as • Git extensions • Source tree • Tortoise Git
  4. GitHub, Inc. is a United States-based global company that provides

    hosting for software development version control using Git. It is a subsidiary of Microsoft What is Github
  5. changes server changes checkout changes changes changes changes origin It’s

    not necessary to have a central location to store all the versions of a project, instead developers and programmers copy (called clone) the main project to their local hard drive, so everyone has a physical mirrored copy of it to work on.
  6. Create a repo Go to Github.com -> Click on +

    -> Click on `New Repository` -> Give repository name -> Click `Create repository`
  7. > git init > git remote add origin <origin_url> --

    do your changes -- > git add . > git commit -m "first commit" > git push -u origin master
  8. changes YourRepo origin > git clone <origin_url> -- do your

    changes -- > git add . > git commit -m "initial commit" > git push –u origin master Clone a repo 1 2 3
  9. > git clone <origin_url> -- do your changes -- >

    git add . > git commit -m "initial commit" -- add upstream url, get changes from upstream -- > git remote add upstream <upstream_url> > git fetch upstream --all > //git pull > git push –u origin master
  10. Branches > git branch //lists all branches > git branch

    <new-branch> //create new > git checkout <new-branch> //switch to > git checkout -b <new-branch> //create + switch
  11. merge > git checkout master //switch to > git merge

    new-feature //merge new-feature to master > git branch -d new-feature //delete new-feature
  12. Merge conflict <<<<<<< HEAD this is some content to mess

    with content to append ======= totally different content to merge later >>>>>>> new_branch_to_merge_later $ git merge new_branch_to_merge_later Auto-merging merge.txt CONFLICT (content): Merge conflict in mer ge.txt Automatic merge failed; fix conflicts and then commit the result. File > < terminal
  13. rebase > git checkout master > git merge feature >

    git checkout feature > git rebase master Merge vs rebase
  14. GIT terminology Branch A version of the repository that diverges

    from the main working project. Repository A repository is a folder whose contents are tracked by git. It is also known as a repo, in simple terms. Master The primary branch of all repositories. All committed and accepted changes should be on the master branch. You can work directly from the master branch, or create other branches. Clone A clone is a copy of a repository or the action of copying a repository. Commit Adding/saving the changes to the local repository
  15. HEAD HEAD is a reference variable used to denote the

    most current commit of the repository in which you are working. When you add a new commit, HEAD will then become that new commit. Push Updates a remote branch with the commits made to the current branch. You are literally “pushing” your changes onto the remote. Rebase When rebasing a git commit, you can split the commit, move it, squash it if unwanted, or effectively combine two branches that have diverged from one another. Merge Taking the changes from one branch and adding them into another (traditionally master) branch.