Download - Git, A Primer
INSTALLING GIThttp://git-scm.com/downloads
GLOBAL CONFIGURATIONMandatory
$ git config global user.username "praveenc"$ git config global user.name "Praveen C"$ git config global user.email "[email protected]"
Optional, but good to have
$ git config global core.editor "vim"$ git config global core.autocrlf "false"$ git config global color.ui "auto"$ git config global color.diff "auto"$ git config global color.branch "auto"$ git config global color.interactive "auto"
GIT ALIASESMost common
$ git config global alias.co checkout$ git config global alias.br branch$ git config global alias.ci commit$ git config global alias.st status
$ git config global alias.unstage 'reset HEAD '$ git config global alias.last 'log 1 HEAD'
E.g.
$ git co developmentSwitched to branch 'development'
External commands
$ git config global alias.visual "!gitk"
CLONING REPOSITORIESgit clone [url]:reponame
E.g.
$ git clone [email protected]:platform.gitCloning into 'platform'...remote: Counting objects: ..., done.remote: Compressing objects: ..., done.remote: Total ..., reused ... (delta ...)Receiving objects: 100% (...), 42.25 MiB | 15.57 MiB/s, doneResolving deltas: 100% (...), done.Checking connectivity... done.Checking out files: 100% (...), done.
VERIFYING REMOTES (SOURCE)View remote props
$ git remote vorigin [email protected]:platform (fetch)origin [email protected]:platform (push)
$ git remote show origin* remote origin Fetch URL: [email protected]:platform Push URL: [email protected]:platform HEAD branch: master Remote branches: development tracked master tracked Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (up to date)
CHECKOUT REMOTE BRANCHView remote branches
$ git branch r origin/HEAD > origin/master origin/development origin/master
Check-out remote branch 'development'
$ git branch* master
$ git checkout developmentSwitched to a new branch 'development'
$ git branch* development master
$ git statuson branch developmentnothing to commit, working directory clean
GIT COMMIT WORKFLOW
ADD FILES TO STAGING AREAAdding files
$ git add .
$ git add A
$ git add all
$ git add js/*.js$ git add *.txt
Diff
$ git diff
$ git diff staged
COMMITTING CHANGESCommitting a staged change
$ git commit m "Added readme.txt"
Add to staging and commit
$ git commit a m "Added readme.txt"
MANAGING CHANGESUnstaging changes
$ git reset HEAD [filename]
Unmodifying a modified file
$ git checkout [filename]
** WARNING: You'll lose all changes (un-recoverable) **Amending commits
$ git commit m "NM0000 fixed something"$ git add forgotten_file$ git commit amend
VIEW COMMIT HISTORYdefault log view
$ git logcommit ca82a6dff817ec66f44342007202690a93763949Author: Praveen Chamarthi [[email protected]]Date: Tue Mar 12 21:52:11 2015 0700
changed the version number
detailed log
$ git log p 1commit a4ef8f2c37c0408b7c69f66f95c796ea64e4bbafAuthor: debug [[email protected]]Date: Wed May 13 13:36:11 2015 0400 added readme.txt
diff git a/readme.txt b/readme.txtnew file mode 100644index 0000000..709087a /dev/null+++ b/readme.txt@@ 0,0 +1 @@+thiasdfkajsdfadfl;asdfa
SYNC CHANGES WITH SERVERPush & Pull
$ git push (push to remote repo)
$ git fetch (fetch only, no merge)$ git pull (git fetch + git merge)
git pull = git fetch + git merge
GIT BRANCHINGCheckout a remote branchView remote branches
$ git branch r origin/HEAD > origin/master origin/development origin/master
Checkout remote branch
$ git checkout [branchname]
E.g.
$ git checkout development
GIT BRANCHINGWorking with local branches
$ git checkout development$ git branch* development master
create local branch using -b flag
$ git checkout b NM3435Switched to a new branch 'NM3435'
$ git branch* NM3435 development master
GIT BRANCHINGMerging local branch to upstream branch
$ git checkout developmentSwitched to branch 'development'
$ git pullUpdating developmentFastforward
$ git merge NM3435Updating 9e11133..a4ef8f2Fastforward readme.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 readme.txt
Deleting a local branch
$ git branch d NM3435Deleted branch NM3435 (was a4ef8f2).
GIT TAGSList tags
$ git tag l5.4.0.5505.4.0.541
$ git tag l '5.4.0*'
Create Tags
$ git tag 5.4.0_HP2 (lightweight tag)$ git tag a 5.4.0_HP2 m "5.4.0 HP2 performance improvements"
Sharing Tags
$ git push tags (push all tags)$ git push origin 5.4.0_HP2 (push specific tags)
GIT TAGSChecking out a Tag
$ git checkout tags/5.4.0_HP2$ git branch a* (detached from 5.4.0_HP2) master remotes/origin/HEAD > origin/master remotes/origin/develop remotes/origin/master
$ git checkout b HP2_FixSwitched to new branch 'HP2_Fix'