Skip to content

Instantly share code, notes, and snippets.

@joshmangum
Forked from akras14/Getting-Cheat-Sheet.md
Created December 14, 2016 22:49
Show Gist options
  • Save joshmangum/0c05e5ad94e5c97f601ee149c97f01ab to your computer and use it in GitHub Desktop.
Save joshmangum/0c05e5ad94e5c97f601ee149c97f01ab to your computer and use it in GitHub Desktop.

#Getting Started with Git

Commands

Getting Started

git init

or

git clone url

Configuration

git config --global color.ui true
git config --global push.default current
git config --global core.editor vim
git config --global user.name "John Doe"
git config --global user.email [email protected]
git config --global diff.tool meld

Working with Local Branch

Branching

# See the list of all local branches
git branch

# Switch to existing local branch
git checkout branchname

# Checkout current branch into a new branch, named new-branch-name
git chekcout -b new-branch-name

# Merge branch-name into the current branch
git merge branchname 

# Soft branch delete, will complain if the branch is not merged
git branch -d branchname

# Hard branch delete, will not complain about nothing. Like rm -rf in bash
git branch -D branchname

Updating Current Branch

Standard Flow

# See all commits
git log

# Pretty commit view, you can customize it as much as you want. Just google it.
git log --pretty=format:"%h %s" --graph

# See status of your current git branch. Often will have advice on command that you need to run
git status

# Short view of status. Helpful for seeing things at a glance
git status -s

# Add modified file to be commited(aka stage the file)
git add filename

# Add all modifeid files to be commited(aka stage all files)
git add .

# Add only text files, etc.
git add '*.txt'

# Tell git not to track file anymore
git rm filename

# Record changes to git. Default editor will open for a commit message. (Visible via git log)
# Once files are commited, they are history.
git commit 

# A short hand for commiting files and writing a commit message via one command
git commit -m 'Some commit message'

# Changing the history :) If you want to change your previous commit, you can, if you haven't pushed it yet to a remote repo
# Simply make new changes, add them via git add, and run the following command. Past commit will be ammended.
git commit --amend

Advanced

git reset
git reset
git reset --hard HEAD
git reset tag
git stash
git stash
git stash pop
git checkout filename #Goes back to the way it was
git diff
git diff HEAD
git diff branch name
git difftool -d
git tag

Working with Remote Branch

git push git push git push -u origin master #The -u tells Git to remember the parameters git push origin branchname git pull origin branchname git remote git remote -v git remote add origin https://gitremote git fetch git fetch git fetch -p

Resources

Reference

Try Github lernGitBranching http://pcottle.github.io/learnGitBranching/?NODEMO Pro Git http://git-scm.com/book

Viewing History

Source Tree Command Line Setup https://answers.atlassian.com/questions/151279/sourcetree-command-line-option tig brew install tig gitk

Merge/Diff Tools

Meld - brew install meld Open Diff p4v Merge - http://git-scm.com/book/en/Customizing-Git-Git-Configuration#External-Merge-and-Diff-Tools InteliJ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment