Skip to content

Instantly share code, notes, and snippets.

@bosskovic
Created November 24, 2014 18:59
Show Gist options
  • Save bosskovic/ede3cda000455b731343 to your computer and use it in GitHub Desktop.
Save bosskovic/ede3cda000455b731343 to your computer and use it in GitHub Desktop.
git notes
# Initialize repository:
git init
# Get current status:
git status
# Add file myfile.txt:
git add myfile.txt
# Commit with a message:
git commit -m "adds myfile.txt"
# Show log:
git log
# Add remote origin:
git remote add origin https://github.com/path_to_repo.git
# Push the default local branch (master) to the remote (origin) and remember branch and remote used (-u):
git push -u origin master
# Check the changes:
git pull origin master
# Compare the changes:
git diff HEAD
# Unstage file
git reset myfile2.txt
# get rid of the changes since last commit:
git checkout -- octocat.txt
# Create branch:
git branch my_new_branch
# Change branch:
git checkout my_new_branch
# Merge branch:
git checkout master
git merge my_new_branch
# Delete branch:
git branch -d my_new_branch
# Purge file from repository history
# filters out all files in .gitignore
git filter-branch --force --index-filter rm --cached --ignore-unmatch `git ls-files -i -X .gitignore` --prune-empty --tag-name-filter cat -- --all
# force pushes to remote
git push origin --force --all
# Remove files from repository without deleting them from the filesystem
# single file
git rm --cached mylogfile.log
# directory
git rm -r --cached directoryName
# everything specified in .gitignore
git rm --cached `git ls-files -i -X .gitignore`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment