Git frequently used

// reset local branch to origin’s state

git checkout {branch}

git reset –hard origin/{branch}

// checkout new branch from origin

git checkout –track origin/{branch}

// merge

git merge {{branch}}

// stash when you need to keep changes but aren’t ready to commit them, say to switch branches or pull new work from team members into your unfinished state

git stash

git stash list

git stash apply {stashName}

// get git remote url

git config –get remote.origin.url
git remote show origin

// create a local branch and switch to it

git checkout -b {name the new branch}

edit, add, commit, push

git push -u origin {new branch name}

// invalidate user so to force password reset

git config –global credential.helper store

// remove already added files/folder from git and add to ignore 

git rm -r –cached file-path

// did hard reset, clean, need it back!? It hasn’t been garbage collected yet, pfew

$ git reflog
1a75c1d… HEAD@{0}: reset –hard HEAD^: updating HEAD
f6e5064… HEAD@{1}: commit: added file2

$ git reset –hard f6e5064
HEAD is now at f6e5064… added file2

// commit everything including untracked

git commit -A

// delete folder from repo

git rm -r folder-name

// output all branches

git branch -a

// delete local branch

git branch branch-name -D

// delete remote branch, just add -r for remote flag

git branch -dr branch-name

// configure git global difftool & mergetool

git config –global diff.tool bc3
git config –global merge.tool bc3
git config –global mergetool.bc3.trustExitCode true

// remove folder from git but don’t delete it

git rm -r –cached myFolder

GIT_TRACE=1 GIT_SSH_COMMAND=”ssh -vvv” git push

Leave a Reply

You must be logged in to post a comment.