User Tools

Site Tools


version_control:git_basics

Git Basics

Clarification

Getting started with git

  • You will need to know how to open an appropriate command line interface (i.e., “terminal” or “command prompt window”) in your OS.

Basic operations

  • Create a git repository in the current directory:
    git init
  • Create a new directory with a git repository in it:
    git init {directory-name}
  • Stage a new file or an existing file that you've changed for the next commit:
    git add {filename}
  • Stage all new and changed files for the next commit:
    git add .
  • “Unstage” a staged file from the next commit:
    git rm --cached {filename}
  • Commit the staged changes:
    git commit -m "A message about this commit."
  • Get status of repository:
    git status
  • Get history of repository:
    git log
  • Delete a file:
    git rm {filename}
  • Rename or move a file:
    git mv {source} {destination}

Don't use Windows' Explorer, Mac's Finder, your Linux file manager, or other shell commands to delete and move/rename files in a repository. Doing so will make git a little grumpy.

Branching and merging

  • A git repository has a default branch called master.
  • Create a new branch:
    git branch {branch-name}
  • Switch to an existing branch:
    git checkout {branch-name}
  • Create a new branch and immediately switch to it:
    git checkout -b {branch-name}
  • Merge changes in another branch into the current branch:
    git merge {branch-name}
  • Delete a branch that you're not currently in:
    git branch -d {branch-name}

Ignoring files

  • To make git ignore some files in your project, create a .gitignore file in the project directory.
    .gitignore
    # Ignore specific files
    nastyfile.txt
    another-nastyfile.docx
     
    # Ignore compiled file(s)
    *.exe
    *.o
     
    # Ignore all files in directory foo
    foo/*

GUI interface

  • git gui: opens a GUI for performing common git functions.
  • gitk: opens a GUI commit browsing tool.
  • Other third party git tools are available.

More git stuff

version_control/git_basics.txt · Last modified: 2016/11/27 23:55 by mithat