Git commands

I will put there list of git commands with a short description.

set user name – git config — global user.name “alx.p”
Set up a new Git repo within the current directory – git init
set up UI color – git config –global color.ui true

// Logs, History
show commits – git log
what changed from last commit – git diff
difference between last commit and current state – git diff HEAD
staged changes -git diff HEAD “ostrich.html”
see changes in files - git log –online -p
changes between branches – git diff master branch_name
check who did what in specific file – git blame index.html –date short
stop tracking file, but leave locally – git rm –cached file_name

// Commits
stage folder – git add css/
stage – git add “filename”, git add . (all)
stage and commit – git commit -a -m “ok”
stage only modified files – git add -u
unstage – git reset “filename”
modify last commit – git commit — amend -m “updated”
undo/rollback the commit, and put the files back in staging – git reset –soft HEAD^
remove the most recent commit – git reset –hard HEAD^
discard/undo changes to some files – git checkout — “cats.html” “index.html”
discard/undo changes to all files git stash save –keep-index then git stash drop
to remove untracked files / directories do: git clean -fdx where -f – force, -d – directories too , -x – remove ignored files too ( don’t use this if you don’t want to remove ignored files)
ignore local changes of file – git update-index –skip-worktree “file_name” or git update-index –assume-unchanged “file_name”

// Branches
create new branch – git branch newbranch
switch to the new branch – git checkout newbranch
megre bracnh to master: git checkout master, git merge newbranch
create and switch to new branch – git chekout -b mynewbranch
get all remote branches – git branch -r
check stale branches that are tracking “origin” – git remote show origin
clean up local branch references – git remote prune origin
merge clean branch to master - git merge “branch_name”

// Merge, Rebase
get last changes and merge them – git pull
push from branch to origin repo- git push origin branch

get remote branch data to temporary folder(without merging) – git fetch
move own master commits after fetched data – git rebase origin/master
merge himself to the following branch – git rebase master

checkout the status for conflicts – git status
fix, then mark confilct as resolved - git add “file_to_resolve”
complete the rebase if it’s all good in da hood – git rebase –continue

// Remote repo
add address as the origin repo – git remote add origin git@example.com:example/petshop.git
send to “origin”. -u used for origin will be the default - git push -u origin master
clone a repo – git clone git@example.com:example/petshop.git
list of remotes – git remote -v
delete branch on origin – git push origin :branchname

// Tags
previous version number – git tag
create tag with new version and commit – git tag -a “v1.3.2″ -m “ss”
push tag to origin - git push –tags
retreieve tag – git checkout “tagname”

chekout

Share this post:Tweet about this on TwitterShare on Facebook0Share on LinkedIn0Share on Google+0Share on Reddit0Email this to someoneDigg this