Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

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)




git dealing with remotes

Add a remote

git remote add origin https://github.com/user/repo.git
# Set a new remote

git remote -v
# Verify new remote
origin  https://github.com/user/repo.git (fetch)
origin  https://github.com/user/repo.git (push)

Remove remote

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

git remote rm destination
# Remove remote
git remote -v
# Verify it's gone
origin  https://github.com/OWNER/REPOSITORY.git (fetch)
origin  https://github.com/OWNER/REPOSITORY.git (push)



Rename the remote

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)


remote add origin git@gitlab.com:urg3n/mailservice935dovecot.git

git push origin master

undo revert git push

http://stackoverflow.com/questions/1270514/undoing-a-git-push
You need to make sure that no other users of this repository are fetching the incorrect changes or trying to build on top of the commits that you want removed because you are about to rewind history.
Then you need to 'force' push the old reference.
git push -f origin last_known_good_commit:branch_name
or in your case
git push -f origin cc4b63bebb6:alpha-0.3.0
You may have receive.denyNonFastForwards set on the remote repository. If this is the case, then you will get an error which includes the phrase [remote rejected].
In this scenario, you will have to delete and recreate the branch.
git push origin :alpha-0.3.0
git push origin cc4b63bebb6:refs/heads/alpha-0.3.0
If this doesn't work - perhaps because you have receive.denyDeletes set, then you have to have direct access to the repository. In the remote repository, you then have to do something like the following plumbing command.
git update-ref refs/heads/alpha-0.3.0 cc4b63bebb6 83c9191dea8

git for managing web public html directory


On GitServer [ ip:192.168.0.123 ]

useradd gituser1 -m -s /bin/bash

mkdir -p /project/ecommerceweb
chown -R gituser1:gituser1 /project


cd /project/ecommerceweb
git init --bare

Note:-To have separate worktree

vim /project/ecommerceweb/hooks/post-receive

#!/bin/bash
GIT_WORK_TREE=/webdir/web git checkout -f

#<save/exit>

chmod +x /project/ecommerceweb/hooks/post-receive



On git client [ ip:192.168.0.123 ]

#copy your ssh public key to git server for user "gituser1" for passwordless ssh and public/private key based authentication

ssh-copyid gituser1@192.168.0.239

git clone ssh://gituser1@192.168.0.239/project/ecommerceweb
cd ecommerceweb
vim index.php
... < add your code /save/exit> ..

git add . # add files to index
git commit -m "initial commit added index page" #Record changes to the repository
git push origin master #push changes to git server
git status

git remote show origin #shows your remote gitserver url OR use

git config --get remote.origin.url



View changed files in your working repository

## git status

Git log

show all git commits

## git log

Git diff

made changes to tracked files

## git diff

Git branch

list all branches

## git branch


setup git server ubuntu 14.04 lts

install git on both gitserver and client

ssh-copy-id the publickey from client to server
mkdir -p /files/webdir.git
cd /files/webdir.git
git init --bare
chown -R gituser:gituser /files/

##On client-A

git config --global user.name "Joe blog"
git config --global user.email "joe@example.com"

we create our local git repo on /developer/djangoproject

mkdir -p /developer/djangoproject
cd /developer/djangoproject
git init .
git remote add origin root@gitserver:/files/webdir.git

to edit >> git remote set-url origin root@gitserver:/files/webdir.git

echo "hello" > index.html
git add .
git commit -m "first commits"

git push origin master

    Counting objects: 3, done.
    Writing objects: 100% (3/3), 212 bytes | 0 bytes/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To root@gitserver:/files/webdir.git
    * [new branch]      master -> master

   
### On client-B
git clone root@gitserver:/files/webdir.git OR
git clone root@192.168.100.221:/files/webdir.git