Tags

## 
## How to merge DEVELOP(staging) TO MASTER(production)
## 
## Solution #1
git checkout master
git fetch origin master
git rebase origin/master
git merge origin/develop
git status
git push origin master 

## Solution #2
git checkout develop
git pull 
git checkout master
git pull
git merge --no-ff --no-commit develop
# If the merge went well and no conflicts found then ready to merge by using commit.
git commit

## Solution #3
git checkout master
git pull origin master
# Merge branch develop into master
git merge develop
# If there are conflicts then we need to resolve it first
# Once we resolve all the conflicts then it is now ready to push to master
git push origin master
------------------------------------------------------
#
# How to UNDO COMMITS?
#
What if, after pushing your commit to the remote repo, you want to undo it? There are a couple of ways.
You can revert the entire commit:
$ git revert de4bbc49eab

#
# How to revert to the working commit version?
# 
Use the git reset hard command

$ git reset --hard fa63d17
HEAD is now at fa63d17 Revert to working commit

$ git status
On branch master
Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
nothing to commit, working tree clean

$ git push -f origin master
------------------------------------------------------
#
# How to fix local out of date?
#
$ git remote show origin
  * remote origin
  Fetch URL: ssh://git@webdev.mycompany.com.com/blog_app.git
  Push URL: ssh://git@webdev.mycompany.com.com/blog_app.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (local out of date)

If the local is out of date then, execute "git fetch/pull" in order to update.
$ git fetch origin master
remote: Counting objects: 173, done.
remote: Compressing objects: 100% (173/173), done.
......
......
$ git status
On branch master
Your branch is behind 'origin/master' by 29 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
nothing to commit, working tree clean

$ git pull
remote: Counting objects: 19, done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 19 (delta 5), reused 0 (delta 0), pack-reused 0
......
......

To verify if the repo is the latest, run the command git remote show origin
$ git remote show origin
  * remote origin
  Fetch URL: ssh://git@webdev.mycompany.com.com/blog_app.git
  Push URL: ssh://git@webdev.mycompany.com.com/blog_app.git
  HEAD branch: master
  Remote branch:
    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)
------------------------------------------------------
#
# How to change the remote Git repository for origin
# 
$ git remote -v
origin  ssh://git@webdev.mycompany.com/blog_app.git (fetch)
origin  ssh://git@webdev.mycompany.com/blog_app.git (push)
Change the URI (URL) for a remote Git repository
$ git remote set-url origin git@beta.mycompany.com/blog_app.git
$ git remote -v
origin  ssh://git@beta.mycompany.com/blog_app.git (fetch)
origin  ssh://git@beta.mycompany.com/blog_app.git (push)
------------------------------------------------------
#
# How to add upstream Git repository
#
$ git remote add upstream ssh://593fa9b189f5cfb6190000b8@angularblogexpress-sudogem.rhcloud.com/~/git/angularblogexpress.git/


# Clone a repo:
git clone git@github.com:projectname/subtitle   

# If you create new files:
git add -A (add’s all files, if you only want to add specific ones reference their path)   

# commit changes you made to existing files:
git commit -am “insert a comment about changes here”  (‘a’ is for all, ‘m’ for message)   
------------------------------------------------------
# push origin repo:
git push    
------------------------------------------------------
# pull origin repo (when someone else makes changes):
git pull   
------------------------------------------------------
#
# Update the codebase in your repo
#
1. git commit -am '#taskNumber your commit message'
2. git fetch origin xxx
3. git rebase origin/xxx
if success
  git push origin xxx
else
  if conflict found then manually resolve it
		then, git add {file} to mark resolution. 
		if all conflicts fixed, then git rebase --continue   
Note: After resolving the conflicts dont use 'git commit' command instead 'git add'
------------------------------------------------------
#
# Switch to another branch(from xxx to yyy)
#
git status
git fetch origin xxx
git rebase origin/xxx
git checkout yyy ---to switch to yyy branch   

# Create the branch on your local machine and switch in this branch :
git checkout -b {branch}

# Push the branch on github :
git push origin {branch}

# Discard unstaged changes in git
git checkout path/to/file/to/revert.html

NOTE: If the file is already staged, you can reset it:
git reset HEAD or git reset HEAD filename
git checkout -- filename 

# How to remove the untracked files
# To know what will be deleted before actually deleting:
$ git clean -d -n

It will output something like:
Would remove README.md
Would remove index.html

# To delete everything listed in the output of the previous command:
git clean -d -f
Removing README.md
Removing index.html

# How to see code changes after git pull from master branch?
$ git fetch origin master or git fetch   # Load changes from remote server
$ git status
On branch master
Your branch is behind 'origin/master' by 7 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
nothing to commit, working tree clean

# Before git pull need to check what are the changes.
$ git diff master origin/master



Advertisements