Tuesday, May 5, 2015

Some Git notes from my experiences

BASIC BRANCH COMMANDS

git branch -- lists off all current branches
git brach -- creates a new branch bases upon the currently checkedout branch
git checkout -- switches to that branch name
git branch -d -- deletes a branch by name

To Merge BranchB into BranchA (or master)
1. git checkout BranchA
2. git merge BranchB
3. git branch -d BranchB

CLONE does checkout too
git clone <{name}>

git branch

CHECKS OUT EXISTING BRANCH
git checkout

CREATES A NEW BRANCH AND CHECKS IT OUT
git checkout -b

DELETES A BRANCH
git branch -d

DELETES A BRANCH (forcefully)
git branch -D

DELETE REMOTE BRANCH
git push origin :shopping_cart


MERGES THE INTO CURRENT BRANCH
git merge

MARKING A CONFLICT AS RESOLVED
git add

MAKING A BRANCH FOLLOW (or TRACK) A REMOTE BRANCH
git branch --track branch-name origin/branch-name

DIFF

CodeSchool GitReal DIFF

git diff HEAD^
git diff HEAD^^
git diff HEAD~5
git diff HEAD^^..HEAD

git log --oneline
git log --oneline -p

CodeSchool GitReal DIFF

git rm
git status
git commit -m "stuff"

TO UNTRACK A FILE (only deleted from the repo not from the file system)

git rm --cached development.log

COMMITS

ADDING A COMMIT

git add .
git commit -m "My Message"

SAME AS ABOVE WITH ONE COMMAND

git commit -am "My Message"

APPENDING A COMMIT

git commit --append -am "My Message"


DELETE THE LAST COMMIT (don't do this after a PUSH!!!)

git reset --hard HEAD^
DELETE MORE THAN ONE COMMIT add more ^ to the end


UNDO THE LAST COMMIT BACK INTO STAGE (don't do this after a PUSH!!!)

git reset --soft HEAD^
KINDA LIKE git commit --amend -m "commit message"

BLOWS AWAY ALL CHANGES SINCE LAST COMMIT

git checkout -- file.txt

REMOVING ITEMS FROM THE STAGE


git reset HEAD file.txt

REMOTES

git remote add
git remote rm

LINKING LOCAL BRANCH TO REMOTE BRANCH
git push origin shopping_cart

VIEWING REMOTE BRANCHES
git branch -r

REMOTE SHOW
git remote show origin

DELETE REMOTE BRANCH
git push origin :shopping_cart

CLEANUP STALE BRANCHES
git remote prune
git remote prune origin

TAGS

GETTING CODE FROM A TAG

git checkout

TO CREATE A TAG

git tag -a -m "comment"

TO PUSH A TAG

git push --tags

UNDOING CHANGES

Undoes all changes in current branch
git checkout -- .

Unstage a file
git reset HEAD -- path/filename.ext

Undo a specific file that has been staged
git reset HEAD -- path/filename.ext
git checkout -- path/filename.ext

Undo a specific unstaged file
git checkout -- path/filename.ext
git clean -df path/filename.ext

Undoing an unstaged folder
Just delete the folder from the file structure

No comments:

Post a Comment