Version Control/Git

From Wikiversity
Jump to navigation Jump to search
Git logo

Git is a distributed revision control software used by many open source projects. This learning resource is meant to help students learn to use it so that they can collaborate with other participants on software projects at Wikiversity.



  1. YouTube: Introduction to Git
  2. YouTube: Git Tutorial 1 - How to Download and Install Git
  3. YouTube: Git Tutorial 2 - Config Our Username and Email
  4. YouTube: Git Tutorial 3 - Creating Our First Repository
  5. YouTube: Git Tutorial 4 - Commit
  6. YouTube: Git Tutorial 5 - Adding Files and the Commit Log
  7. YouTube: Git Tutorial 6 - Git Workflow
  8. YouTube: Git Tutorial 7 - How to Edit Files
  9. YouTube: Git Tutorial 8 - Viewing the Changes That You Made
  10. YouTube: Git Tutorial 9 - Comparing the Staging Area with the Repository
  11. YouTube: Git Tutorial 10 - How to Delete Files
  12. YouTube Git Tutorial 11 - How to Move and Rename Files
  13. YouTube: Git Tutorial 17 - Github
  14. YouTube: Git Tutorial 18 - Pushing to a GitHub Repository


Git Installation[edit]

  1. Download Git from
  2. Install Git. (MacOS: brew install git)

Copy an existing remote repository[edit]

  1. Clone a remote repository.
    • Select a local folder to copy the repository into, or create a new folder if you prefer. The repository will be copied as a subdirectory of the selected folder.
    • At a command or terminal prompt, navigate to the selected folder.
    • Clone the repository using the command:
      git clone URL_TO_REPO. See also: git pull and git fetch

Create a local repository[edit]

  1. Initialize a folder for Git.
    • Select a local folder to add to Git, or create a new folder if you are starting a new project.
    • At a command or terminal prompt, navigate to the selected folder.
    • Initialize the folder using the command:
      git init

Make Local Changes and Update remote Repositories[edit]

Add local changes.

  1. Stage files.
    • Add files to the folder or modify existing files.
    • Add new and modified files to the git staging area using the command:
      git add . or git add some_modified_file.txt
  2. Commit changes.
    • Commit changes into the local repository using the command:
      git commit -m "<some message>"
  3. Connect to a remote repository.
    • Connect to a remote repository using the command:
      git remote add <name> <url>
  4. Push changes to a remote repository.
    • Push changes from your local repository to a remote repository using the command:
      git push

Retrieve Remote Changes[edit]

  • Pull/get changes from a remote repository to have latest version of the code
    • Pull/get changes from a remote repository to your local repository using the command:
git pull or git pull <name> <branch>
git pull -v (for more verbose output)
git fetch
gfind $1 -name ".git" | gsed -r 's|/[^/]+$||' | parallel "echo {}; git -C {} pull" (git pull all your repos in parallel, MacOS version)
  • Pull subdirectories:
ls | parallel git -C {} pull (assuming all sub-dirs are git repositories)[1]
ls | parallel git -C {} fetch

Repository information[edit]

  • git remote -v or git remote show origin or git config --get remote.origin.url[2]

Git log[edit]

  • git log --oneline
  • git log --pretty=format:"%h - %an, %ar on %cd: %s"
  • Show modifications to a file:git log --follow -p FILE_TO_SHOW[3] or git blame FILE_TO_SHOW
  • git shortlogs
  • List developers: git shortlogs -sne[4]

Git show[edit]

  • git show 3c88ad72430


  • List tags:
    • git tag (show releases)
    • List tags with dates: git log --tags --simplify-by-decoration --pretty="format:%ci %d"[5]. Just can also add taglog = log --tags --simplify-by-decoration --pretty='format:%ci %d' (note the single-, NOT double-quotes) in the [alias] section of your .gitconfig file.
    • git log --decorate=full --simplify-by-decoration
  • Print lines matching a pattern:git grep TEXT_TO_SEARCH

Tips and Tricks[edit]

  • To avoid using --pager in all git log commands, add the following line to your ~/.bash_profile file:[6]
    export GIT_PAGER=cat


  1. Clone some public repositories
  2. Learn what is a merge or pull request:
  3. Create your first website in GitHub/Website Hosting using git
  4. Read StackOverflow questions about Git:

See Also[edit]