GIT - mosinn/DOCS-n-Snippets-n-Steps GitHub Wiki
git branch --show-current
// File Names List DEVELOP vs CURRENT - WITH Line STATS
git diff --stat --color develop..feature\new
// File Names List - CURRENT vs DEVELOP
git diff --name-status develop
// File Names List - anyBranch1 vs anyBranch2Current
git diff --name-status anyBranch1..anyBranch2Current
NOTE: If list of diffs is large, terminal buffers output and stops on blinknig : => Press SPACE to paginate and at 'END', DONT press ESC..Just press 'Q'
git config --global user.name "Sam Smith"
git config --global user.email [email protected]
git clone <username@host:/path/to/repository>
git pull
git checkout develop/xxx
git init
git checkout <branchname>
git checkout -b <branchname>
git branch --list -a
git status
git log --author=tim --pretty=oneline --decorate --all
git diff <sourcebranch> <targetbranch>
git diff
git reset --hard origin/master
git push origin :<branchname>
git branch -d <branchname>
git grep "foo()"
git diff HEAD^^ HEAD <path of file>
git add .
*=saferThan.dot .= nu+modified , -u=modified+deleted-nu, -A=everything:nu+modified+deleted
git commit -m "STORY123 - my message "
git push -u origin <branchname>
..remain in your local branch where you want to have latest remote changes
git merge <remote develop branch where others have committed changes>
Create a local branch from latest dev, then set its upstream tracking so that latest changes can be pulled
git checkout <dev>
git branch -b <my local feature>
git branch --set-upstream-to=origin/develop/19.4.0 feature/<my local feature>
..keep working locally and pulling latest now
..finally push to origin, for others to see nu local branch of yours
git push -u origin <my local feature>
.. if local branch was named with temporary name till story was wip, use below when real name is known later
git push origin local-name:remote-name
.. in case we didnt clone from remote and just are inventing a new branch for POC:-
git remote add origin <remote server>
git stash
git checkout feature/dev
git pull
create and checkout new branch out of latest dev, locally (-b flag if used makes it single step one)
git branch feature/my-new-local-branch
git checkout feature/my-new-local-branch
git branch --set-upstream-to=origin/dev/00.1.0 feature/my-new-local-branch
git branch --set-upstream-to=origin/rel/00.1.0 feature/my-new-local-branch
git stash pop
Copy files from one branch to the one we are on - Works fully if we goto older commit on web git and copy all relevant file name paths and use below to transfer
git checkout feature/my-older-local-branch projName/path/...../js/.../abcUtil.js
....
Amend last commit (try only on feature branch of yours) , to change commit message or replace a whitespace file mess
..after a bad commit
.. update the file you want to change in last commit, locally
discard all other changes to keep tree clean with only missed changes dirty
git add .
git commit --amend
..update commit message in vi above opens
git push -f origin HEAD
git reset HEAD~1
git branch -m feature/newName
git branch -m old-name new-name
git push origin :old-name new-name
RENAME branch - Reset the upstream branch for the new-name local branch.Switch to the branch and then
git push origin -u new-name
git push -d <remote_name> <branchname>
git branch -d <branchname>
- Create 'squash' branch from develop - feature/OCPS-0001-MyFeature1-Squash
- Create 'eventual feature' branch from develop - feature/OCPS-0001-MyFeature1-Eventual
- Locally keep working and committing freely in feature/OCPS-0001-MyFeature1-Squash
- Finally when done:
-
git checkout feature/OCPS-0001-MyFeature1-Eventual
-
git merge --squash feature/OCPS-0001-MyFeature1-Squash
-
commit with -m and push as usual
-
delete the feature/OCPS-0001-MyFeature1-Squash branch
-
Raise PR from feature/OCPS-0001-MyFeature1-Eventual to develop