Tags

How to add and commit a
add & commit
You can propose changes (add it to the Index) using
git add {filename} or git add .
git commit -am “Commit message”
Now the file is committed to the HEAD, but not in your remote repository yet.

————————————————————————————
Pushing changes
Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository,
execute: git push origin master

git fetch origin
git diff master origin/master
git merge origin/master
————————————————————————————
Comparing two files
git diff HEAD {filename}
————————————————————————————
Check if your current branch has any updates from remote
git remote show origin
————————————————————————————
In my local dev,
git add filename
git push origin master
git remote show origin

In server02,
git remote show origin
simply execute: git pull
or
git fetch origin
git reset –hard origin/master

The third options is to discard the local changes using: git reset –hard
————————————————————————————
List remote branches
git ls-remote ssh://git@mysite.com/myapp.git OR SIMPLE git ls-remote in your current git repo
output:
2be5142f0e05b495a7708dad41e9fbff0096308a HEAD
bfb71abf9e00224e27166b27b28d49d747facd2d refs/heads/develop
e2be5142f0e05b495a7708dad41e9fbff0096308 refs/heads/master

Or like this:
$ git branch -r
output:
origin/HEAD -> origin/master
origin/master
————————————————————————————
How to update your master branch ?
$ git branch
* no branch
master
so, need ta mo switch sa master branch para makuha ang updated source files
$ git checkout master
Switched to branch ‘master’
Your branch is behind ‘origin/master’ by 1 commit, and can be fast-forwarded.

$ git remote show origin
* remote origin
Fetch URL: ssh://git@mycompany.com/httphelper.git
Push URL: ssh://git@mycompany.com/httphelper.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 it is out of date then execute git pull in order to update it
$ git pull

$ git remote show origin
* remote origin
Fetch URL: ssh://git@mysite.com/httphelper.git
Push URL: ssh://git@mysite.com/httphelper.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 checkout a branch(master) ?
git branch
output: * master
git fetch origin
output:
remote: Compressing objects: 100% (29/29), done.
From ssh://mysite.com/api
* [new branch] develop -> origin/develop

git checkout {mybranch} e.g git checkout develop
————————————————————————————
after sa git fetch
then git diff master origin/master ### for checking
then git merge origin/master

Create the branch on your local machine and switch in this branch :
git checkout -b [name_of_your_new_branch]

Push the branch on github :
git push origin [name_of_your_new_branch]

Discard unstaged changes in git: $ git checkout — {filename}
Discard all changes: $ git checkout .
But if the file is already staged, you will reset back to HEAD:
$ git reset HEAD
————————————————————————————————————-
How to change the remote Git repository for origin
$ git remote -v
origin ssh://git@mysite.com/testapp.git (fetch)
origin ssh://git@mysite.com/testapp.git (push)
## Change the URI (URL) for a remote Git repository
$ git remote set-url origin git@github.mycompany.com:MyGroup/myrepo.git
————————————————————————————————————-
git config –global push.default simple
git push or git push –set-upstream origin email_trigger
————————————————————————————————————-
zz – move current line to the middle of the screen
zt – move current line to the top of the screen
shift g – end of file
gg – top of file
————————————————————————————————————-
In my local dev machine:
git checkout master —to switch to master branch
git pull

From email_trigger branch:
git status
git fetch origin
git rebase origin/ui_changes
git checkout ui_changes —to switch to ui_changes branch
————————————————————————————————————-
From git gui, select the emailer branch

current branch,
git fetch origin
git rebase origin/master
————————————————————————————————————-
Force delete the branch: git push origin –delete ldap_authentication
git rebase origin/connections_trigger
git rebase –continue
git rebase –abort
git rebase –skip
————————————————————————————————————-
git checkout -b {mybranch}
git checkout
————————————————————————————————————-
How to update the remote git repo
$ git commit -am ‘#taskNumber a very detail commit message’
$ git fetch origin
$ git rebase origin/develop
if SUCCESS
git push origin develop
else
if naay conflict, manually resolve and then
git add {conflictFile} to mark resolution. Note: no git commit command
if all conflicts fixed, then
git rebase –continue
git push origin develop
————————————————————————————————————-
How to update your local repo
$ git fetch origin master ## OR git fetch origin
$ git status
On branch master
Your branch is behind ‘origin/master’ by 4 commits, and can be fast-forwarded.
(use “git pull” to update your local branch)
nothing to commit, working tree clean
$ git pull -v
Updating ed20586..dde2ac6
Fast-forward
public/css/app.css | 16 ++++++++++++++–
public/js/components/index.jsx | 19 ++++++++++++——-
2 files changed, 26 insertions(+), 9 deletions(-)

————————————————————————————————————-
How to preview first before pushing?
* git diff 0da94be..59ff30c
* git diff origin/develop
————————————————————————————————————-
This will list out your local comment history (not yet pushed) with corresponding message
git cherry -v

————————————————————————————————————-
git fetch origin develop
git rebase origin/develop
————————————————————————————————————-
How to merge DEVELOP(staging) TO MASTER(production)
Solution 1
git checkout master
git fetch origin
git rebase origin/master
git push origin master
# Note: The major benefit of rebasing is that you get a linear and much cleaner project history.

Solution 2
git checkout master
git pull origin master or git pull origin –rebase
# Merge branch develop into master
git merge develop
git push origin master
# If there are conflicts then we need to resolve it first
# Once we resolve all the conflicts it is now ready to push to master
git push origin master

# breaking something on the merge then abort it.
git merge –abort
————————————————————————————————————-
$ git clean -d -x -n
This removes untracked files, including directories (-d) and files ignored by git (-x).

$ git clean -d -x -f
Perform the delete operation

$ git checkout — js/app.js
$ git diff HEAD js/app.js
————————————————————————————————————-
$ npm install
$ bower install
$ grunt copy
$ grunt sass
$ grunt deploy (to run all task)
————————————————————————————————————-
How to update/sync your fork repo from the original repo?
$ cd myforkedApp
$ git remote -v
origin git@github.com:sudogem/rdash.git (fetch)
origin git@github.com:sudogem/rdash.git (push)
$ git remote add upstream git@github.com:tuxrace/rdash.git
$ git remote -v
origin git@github.com:sudogem/rdash.git (fetch)
origin git@github.com:sudogem/rdash.git (push)
upstream git@github.com:tuxrace/rdash.git (fetch)
upstream git@github.com:tuxrace/rdash.git (push)
$ git fetch upstream
$ git merge upstream/develop
———————————————————
artheman@ub3c:/var/www/_js/rdash(develop)$ git pull –rebase -v
remote: Counting objects: 1, done.
remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (1/1), done.
From github.com:sudogem/rdash
94545e9..d9e083f develop -> origin/develop
3769d24..94545e9 master -> origin/master
Changes from 067377061d2ebbd9ad19667c6b71085d9fd3cd56 to d9e083ff9a03e4ef68937860f9d8dde8eec2bce1:
First, rewinding head to replay your work on top of it…
Applying: testing
Applying: testnews
Applying: new
artheman@ub3c:/var/www/_js/rdash(develop)$
————————————————-

How to see code changes BEFORE 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

————————————————————————————————————-
How to change/update the git comments?
Will open your editor, allowing you to change the commit message of the most recent commit.
git commit –amend

————————————————————————————————————-
$ vi ~/.bash_profile ## or vi ~/.bashrc

#!/bin/bash
alias cls='clear;clear'

alias gitlogtree="git log -n 10 --graph --decorate -30 --all --date-order --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%C(cyan)%h%Creset %C(black bold)%ad%Creset%C(auto)%d %s'"

alias gitlog="git log -n 10 --pretty=format:'%Cgreen%h%Creset%x09%C(cyan)%an%Creset%x09%C(black bold)%ad%Creset%x09%s'"

How to add and commit a
add & commit
You can propose changes (add it to the Index) using
git add {filename} or git add .
git commit -am “Commit message”
Now the file is committed to the HEAD, but not in your remote repository yet.

————————————————————————————
Pushing changes
Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository,
execute: git push origin master

git fetch origin
git diff master origin/master
git merge origin/master
————————————————————————————
Comparing two files
git diff HEAD {filename}
————————————————————————————
Check if your current branch has any updates from remote
git remote show origin
————————————————————————————
In my local dev,
git add filename
git push origin master
git remote show origin

In server02,
git remote show origin
simply execute: git pull
or
git fetch origin
git reset –hard origin/master

The third options is to discard the local changes using: git reset –hard
————————————————————————————
List remote branches
git ls-remote ssh://git@mysite.com/myapp.git OR SIMPLE git ls-remote in your current git repo
output:
2be5142f0e05b495a7708dad41e9fbff0096308a HEAD
bfb71abf9e00224e27166b27b28d49d747facd2d refs/heads/develop
e2be5142f0e05b495a7708dad41e9fbff0096308 refs/heads/master

Or like this:
$ git branch -r
output:
origin/HEAD -> origin/master
origin/master
————————————————————————————
How to update your master branch ?
$ git branch
* no branch
master
so, need ta mo switch sa master branch para makuha ang updated source files
$ git checkout master
Switched to branch ‘master’
Your branch is behind ‘origin/master’ by 1 commit, and can be fast-forwarded.

$ git remote show origin
* remote origin
Fetch URL: ssh://git@mycompany.com/httphelper.git
Push URL: ssh://git@mycompany.com/httphelper.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 it is out of date then execute git pull in order to update it
$ git pull

$ git remote show origin
* remote origin
Fetch URL: ssh://git@mysite.com/httphelper.git
Push URL: ssh://git@mysite.com/httphelper.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 checkout a branch(master) ?
git branch
output: * master
git fetch origin
output:
remote: Compressing objects: 100% (29/29), done.
From ssh://mysite.com/api
* [new branch] develop -> origin/develop

git checkout {mybranch} e.g git checkout develop
————————————————————————————
after sa git fetch
then git diff master origin/master ### for checking
then git merge origin/master

Create the branch on your local machine and switch in this branch :
git checkout -b [name_of_your_new_branch]

Push the branch on github :
git push origin [name_of_your_new_branch]

Discard unstaged changes in git: $ git checkout — {filename}
Discard all changes: $ git checkout .
NOTE: If the file is already staged, you need to reset it, first:
$ git reset HEAD ; git checkout —
————————————————————————————————————-
How to change the remote Git repository for origin
$ git remote -v
origin ssh://git@mysite.com/testapp.git (fetch)
origin ssh://git@mysite.com/testapp.git (push)
## Change the URI (URL) for a remote Git repository
$ git remote set-url origin git@github.mycompany.com:MyGroup/myrepo.git
————————————————————————————————————-
git config –global push.default simple
git push or git push –set-upstream origin email_trigger
————————————————————————————————————-
zz – move current line to the middle of the screen
zt – move current line to the top of the screen
shift g – end of file
gg – top of file
————————————————————————————————————-
In my local dev machine:
git checkout master —to switch to master branch
git pull

From email_trigger branch:
git status
git fetch origin
git rebase origin/ui_changes
git checkout ui_changes —to switch to ui_changes branch
————————————————————————————————————-
From git gui, select the emailer branch

current branch,
git fetch origin
git rebase origin/master
————————————————————————————————————-
Force delete the branch: git push origin –delete ldap_authentication
git rebase origin/connections_trigger
git rebase –continue
git rebase –abort
git rebase –skip
————————————————————————————————————-
git checkout -b {mybranch}
git checkout
————————————————————————————————————-
How to update the remote git repo
$ git commit -am ‘#taskNumber a very detail commit message’
$ git fetch origin
$ git rebase origin/develop
if SUCCESS
git push origin develop
else
if naay conflict, manually resolve and then
git add {conflictFile} to mark resolution. Note: no git commit command
if all conflicts fixed, then
git rebase –continue
git push origin develop
————————————————————————————————————-
How to update your local repo
$ git fetch origin master ## OR git fetch origin
$ git status
On branch master
Your branch is behind ‘origin/master’ by 4 commits, and can be fast-forwarded.
(use “git pull” to update your local branch)
nothing to commit, working tree clean
$ git pull -v
Updating ed20586..dde2ac6
Fast-forward
public/css/app.css | 16 ++++++++++++++–
public/js/components/index.jsx | 19 ++++++++++++——-
2 files changed, 26 insertions(+), 9 deletions(-)

————————————————————————————————————-
How to preview first before pushing?
* git diff 0da94be..59ff30c
* git diff origin/develop
————————————————————————————————————-
This will list out your local comment history (not yet pushed) with corresponding message
git cherry -v

————————————————————————————————————-
git fetch origin develop
git rebase origin/develop
————————————————————————————————————-
How to merge DEVELOP(staging) TO MASTER(production)
Solution 1
git checkout master
git fetch origin
git rebase origin/master
git push origin master
# Note: The major benefit of rebasing is that you get a linear and much cleaner project history.

Solution 2
git checkout master
git pull origin master or git pull origin –rebase
# Merge branch develop into master
git merge develop
git push origin master
# If there are conflicts then we need to resolve it first
# Once we resolve all the conflicts it is now ready to push to master
git push origin master

# breaking something on the merge then abort it.
git merge –abort
————————————————————————————————————-
$ git clean -d -x -n
This removes untracked files, including directories (-d) and files ignored by git (-x).

$ git clean -d -x -f
Perform the delete operation

$ git checkout — js/app.js
$ git diff HEAD js/app.js
————————————————————————————————————-
$ npm install
$ bower install
$ grunt copy
$ grunt sass
$ grunt deploy (to run all task)
————————————————————————————————————-
How to update/sync your fork repo from the original repo?
$ cd myforkedApp
$ git remote -v
origin git@github.com:devUser1/rdash.git (fetch)
origin git@github.com:devUser1/rdash.git (push)
$ git remote add upstream git@github.com:devUser2/rdash.git
$ git remote -v
origin git@github.com:devUser1/rdash.git (fetch)
origin git@github.com:devUser1/rdash.git (push)
upstream git@github.com:devUser2/rdash.git (fetch)
upstream git@github.com:devUser2/rdash.git (push)
$ git fetch upstream
$ git merge upstream/develop
———————————————————
artheman@ub3c:/var/www/_js/rdash(develop)$ git pull –rebase -v
remote: Counting objects: 1, done.
remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (1/1), done.
From github.com:devUser1/rdash
94545e9..d9e083f develop -> origin/develop
3769d24..94545e9 master -> origin/master
Changes from 067377061d2ebbd9ad19667c6b71085d9fd3cd56 to d9e083ff9a03e4ef68937860f9d8dde8eec2bce1:
First, rewinding head to replay your work on top of it…
Applying: testing
Applying: testnews
Applying: new
artheman@ub3c:/var/www/_js/rdash(develop)$
————————————————-

How to see code changes BEFORE 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

————————————————————————————————————-
How to change/update the git comments?
Will open your editor, allowing you to change the commit message of the most recent commit.
git commit –amend

————————————————————————————————————-
$ vi ~/.bash_profile ## or vi ~/.bashrc

#!/bin/bash
alias cls='clear;clear'

alias gitlogtree="git log -n 10 --graph --decorate -30 --all --date-order --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%C(cyan)%h%Creset %C(black bold)%ad%Creset%C(auto)%d %s'"

alias gitlog="git log -n 10 --pretty=format:'%Cgreen%h%Creset%x09%C(cyan)%an%Creset%x09%C(black bold)%ad%Creset%x09%s'"

Advertisements