Creating New Git Repository
Creating New Git Repository
Creating new git repository: cd wordpress_git git init cd .. cp -ra wordpress/* wordpress_git cd wordpress_git git add . git commit -m "first commit"
Committing code in GIT repo git add filename git commit -m "msg" filename Ignoring any file in any directory of whole git repository: make entries in file .gitignore ! means not files without / are checked aginst basename / means current directory every repo have .git/info/exclude .gitignore and exclude work together. .git/info/exclude will not be cloned.
Configuration of git repositories: git-config name value git-config name git-config -l #set name and value #get current value #get all values
GIT encourages branching: Create a branch: git-checkout -b topic-name master work on this branch Commit and Merge:
git-checkout master git-merge topic-name Delete branch git-branch -d topic-name Merging branches and getting conflict: Two different people work on two different branches: A works on branch A: git checkout master git checkout -b branchA master
B wants to work on his branch: git checkout master git checkout -b branchB master Now the situation is as follows: master / \ branchA branchB
Now we can do two things: Merge and Rebase: Merge: master / \ branchA branchB \ / master
STEPS: A has completed his work he will merge his branch with master and then delete his branch
git checkout master git merge branchA git branch -d branchA B has now completed his work and he want to merge and then delete his branch git checkout master git merge branchB CONFLICT EXIST NOW. B will resolve the conflict and then merge the branchB with master code. Then git branch -d branchB
Rebase: master X \ barnchA -- branchB \ master we relocate the parent of branchA with branchB and pretend that we checkout the branch from branchB. Checking Logs: LOG git-log git-log -p # print difference b/w revisions git-log --stat # statistics git-log file1 file2 file3 # log for specified files Checking differences
# difference b/w commited and current code # difference b/w # # difference b/w current and OTHERBRANCH
Working with others: git-clone #to create the copy of remote directory
git clone ssh://newstage.investmentpal.com/home/ivpl/repo/.git git-pull git-push git-fetch #to get changes from remote directory #to send changes to remote directory #updating our repo with remote repo.