Skip to content

Latest commit

 

History

History
70 lines (69 loc) · 3.94 KB

Git101.md

File metadata and controls

70 lines (69 loc) · 3.94 KB

Tutorial for the Command Line:

  • Install (offline): https://git-scm.com/download/win 

  • Verify installation by typing git –version in the command line Note: I like cmder for my command line to make it a little easier on the eyes https://cmder.net/)

  • Create a local folder for the project and convert it to a git repo:

    • cd C:/repos/my-new-folder
    • git init
  • Create the repo in remote and follow directions to clone into your folder

  • Example - BitBucket instructions:

    • Configure Git for the first time
    • To push existing code to an empty repo
    • Branching
      • NOTE: There must be an initial commit before 'master' is created and/or a branch can be created
      • List all branches in repo: git branch
      • Create a new branch and switch to it: git checkout -b <branch-name>
      • Switch to an existing branch: git checkout <branch-name>
      • Delete unused feature branch locally: git branch -d <branch-name>
    • Working with other people's code
      • Update branch: git pull
      • Merge another branch to your active branch (e.g. latest from develop to your feature branch): git merge <other-branch-name>
      • View diffs for branch: git diff
      • View diffs for file: git diff --base <file-name>
      • Preview changes before merge: git diff <source-branch> <target-branch>
      • Press q to exit diff
        • NOTE: You can use Beyond Compare (or something else) to view diffs
          • Run the following (for Git v.2+ and BC v4+): 
          • git config --global diff.tool bc
          • git config --global difftool.prompt false
          • git config --global difftool.bc.path "C:\Program Files\Beyond Compare 4\BCompare.exe"
          • git config --global merge.tool bc
          • git config --global mergetool.prompt false
          • git config --global mergetool.bc.path "C:\Program Files\Beyond Compare 4\BCompare.exe"
        • To view the diff, run: git difftool --<filename>
        • To view a preview a merge/resolve conflicts, run: git mergetool
        • Note that you won't be able to continue in the command line until you close Beyond Compare
    • Fixing unwanted changes
      • View recent commits: git log
      • Revert local changes to a previous commit:
        • git fetch origin
        • git reset --hard origin/master
      • Replace local changes with the most recent in remote: git checkout -- <file-name>
    • Rename or Move a File
      • NOTE: Do NOT move or rename a file from Windows Explorer and commit it. Git views this as a deletion of the original and creation of a new file, and the file history will be disconnected. Follow the below instructions or refer to the linked article below for help.
      • NOTE: Although moving and renaming a file may seem like separate operations/subjects, Git treats them as the same operation, as you are modifying the path of a file either way.
    • To rename a file, in the command line:
      • cd <parent-folder-of-existing-file>
      • git mv <existing-file-name> <new-file-name>
      • git add --all
      • git commit -m "<issue #>: Renamed <existing> to <new>"
      • git push
    • To move a file, in the command line:
      • cd <parent-folder-of-existing-file>
      • git mv <existing-file-name> <path-to-new-parent-directory>
      • git add --all
      • git commit -m "<issue #>: Moved <file-name> to <new-folder-name>"
      • git push
  • Further reading: This concise article or this one