Practical use of git


git remote add origin https://github.com/devopsnep/localhost.git
git push -u origin master

git fetch  // retrive changes from remote repo ,store them but dont include in local code
git merge
"git pull" is same as "git fetch && git merge"

git branch new-feature
git branch   //shows branches
git checkout new-feature  // switch to branch called new-feature
git add -A
git commit -m "added new features"

git branch is extremely useful for developing features or bugfixes in isolation 
and it can be merged to the central branch

git checkout -b new-feature2  //create branch and switch to it
git checkout -    // similar to 'cd -'


To merge the branch "new-feature" to "master"
git checkout new-feature
// do some changes git add -A and commit

git checkout master
git merge new-feature

// To delete the branch
git branch -d new-feature


###automatic merge fail cases and merge CONFLICT'S:

git status //see which file have conflicts and then open that file 

open file in editor and make changes and  add+commit+push

##git stash

objective is to leave the current uncommitted code as is 
create new bugfix branch do corrections and merge
get back to uncommittted  incomplete code and continue

git checkout -b monthadd
vim month.php
..
git add -A   //stage the changes
##  bugfix need to be done
git stash   ## yesley garirako change lai side lagaucha

git checkout -b bugfixes
//do stuffs
git checkout master
git merge bugfix

// now getting backto leftover code/branch called "months"
git checkout months
git stash apply   // gets back the incomplete code/files
..do coding
git commit -m "months feature added"
git status
..
// done
// Example

git log --oneline  // condenses commits to single line
git log --decorate  
git log --graph  // ASCII graph shows branches and merges 
git log -p  //patch / shows lines deleted and added
git log --start //show number of insertion/deletions
git log --oneline --graph


git log  -3   //show 3most recent commit
git log --after="yesterday"  //commit between now and yesterday
git log --after="2 weeks ago"
git log --after="2/15/17" 
git log --after="2-15-17"
git log --after="2-15-17" --before="yesterday"
git log -i --author="Trevor\|Jane" //filters by author name/email containing work "trevor" or "jane" here -i is ignore case
git log --grep="copyright"  // finds commit that has word copyright
git log -p -S"Math"  //find commit code change that has word "Math" is removed or added
git log -p -GMath\|Random  //same as but using regex to find commit code change that has word Math is removed or added
git log LICENSE.md README.txt //see commits for these two files
 git log master..new-feature // see where master and new-feature branch is diverged



## view and rename remotes

git remote -v
# View existing remotes
origin  https://github.com/OWNER/REPOSITORY.git (fetch)
origin  https://github.com/OWNER/REPOSITORY.git (push)

git remote rename origin destination
# Change remote name from 'origin' to 'destination'

git remote -v
# Verify remote's new name
destination  https://github.com/OWNER/REPOSITORY.git (fetch)
destination  https://github.com/OWNER/REPOSITORY.git (push)




No comments:

Post a Comment