Handy Git Commands
Import an Existing Repo, Hosted on a Remote, eg: BitBucket or GitHub:
cd /your/local/directory git clone git@github.com:reponame/domainname.git
Create a Brand New (Local) Repo, & Add a (Bare) Remote:
cd /your/local/directory git init git add . git commit -m "Begin! Import all existing web files"
Then we add the remote (bare) repository as “origin”, specifying the “master” branch on the remote:
git remote add origin git@github.com:caius/foo.git git push origin master
How Are Things With You?
git status
How’s The Long Distance Relationship Working for Ya?
git remote show git remote show origin
Add Changes to Snapshot & Commit:
git add . git commit -m "Very insightful message."
Or you can do it one step with:
git commit -am "Very insightful message."
(Note that if you’re adding brand new files to the snapshot, you need to do it explicitly with git add, not the git commit -am thing.)
Switch to a Branch:
git checkout branchname
Create a New Branch & Switch to It:
git branch newbranchname git checkout newbranchname
Or you can do it in one step with:
git checkout -b newbranchname
Merge a Branch With Master:
git checkout master git merge branchnametomerge
Delete a Branch:
git branch -d branchnametodelete
Show All Branches:
git branch -a
Show Remote Branches:
git branch -r
Show a Log with Pretty Graphs:
git log --graph --decorate --pretty=oneline --abbrev-commit --all
Simple List of Conflicted Files:
git diff --name-only --diff-filter=U