Command_GIT

Git version

  • git version

  • SSL certificate permission

  • git config --global http.sslVerify=false 

  • Current branch

  • git branch --v

  • Create and checkout new branch

  • git checkout -b <new_branch_name> origin/master

NOTE: Create new branch ‘new_branch_name’ from base branch ‘origin/master’.

  • Checkout only

o   git checkout <NEW-BRANCH-NAME>

  • Clone branch into local

  • Git clone <Branch_URL> -b <Branch_Name_RTY>

NOTE: Clone ‘Branch_Name_RTY’ into the local system.

  • Clone from specific branch: git clone <URL> -b <BRANCH-NAME>

  • Terminal clone: git clone <URL>

  • Add new project in Git

  • git init

  • git add . (dot)

  • git remote add origin <URL>

  • git commit -m “COMMIT-MSG”

  • git push origin master

  • Local branches remotely connect with git. (Make it git project)

  • git init

  • git remote add origin <REPO-URL>

  • Current Status/ file changes

  • git status

  • Show local branch

  • git branch

  • Delete local branch

  • git branch -d <local_branch_name> 

  • Forcefully: git branch -D <local_branch_name> 

  • Move branch from B1 -> B2

  • git checkout <New_Branch_Name>

NOTE: B1 is old and B2 is the new branch name. 

  • Pull Request

  • git pull origin <master>

  • git -c http.sslVerify=false origin < Branch_Name>

  • git pull --all

  • Fetch: git fetch origin master

  • Add file from Unmerged to merged/git (Red to green)

  • Git add *.Java, *.xml, *.* (Bulk file of same types of extension)

  • Git add a.java (Blank_Space) b.java (For different extension multiple file) 

  • Commit message

  • git commit -m <New_Message>

  • git commit --amend (Append into existing or last commit Id) 

  • Push code into branch

  • Git push origin <Branch_Name> 

  • Show code changes specific commit id

  • Step 1: git log (Read commit id or can from UI)

  • Step 2: git show <Commit_Id> (from step 1)

  • Stash code in local

  • git stash save “Message” 

  • Stash list: Git stash list

  • git stash apply stash{0}

  • Check modified code in merged file

  • All file difference: git diff

  • git diff <FULL_FILE_NAME> 

  • Abort last merging

  • Git merge --abort 

  • Cherry-pick

Update ‘story1234’ branch from ‘preprod’ to ‘prod’. (Suppose, I have a local branch ‘story1234’ and push my updated code into branch ‘preprod’. Now, I want to update the same code in ‘prod’ using cherry-pick. Then first, I will create a new branch ‘story1234_cherrypick’ and cherry-pick using commit-id into branch ‘story1234_cherrypick’.

  • git checkout prod

  • git checkout -b <story1234_cherrypick>

  • git status (No modified file will show for commit)

  • git cherry-pick <Commit-id> (Commit id from UI or ‘git log’>

  • git push origin < prod>

  • Raise PR for code changes into preprod

  • git checkout -b <story_12> origin/preprod

  • git push origin <story_12>

Error "Fatal: Not possible to fast-forward, aborting"

git pull --no-ff

  • Conflict issue and bulk of file changes then remove all local changes

  • Git checkout -b <new_branch_name> origin/B1

  • Git checkout . (Dot, for Remove all local changes)

  •  Branch commit message

  • git log -1 (Show last commit with all details) 

  • git log -1 –pretty=%B (Only show last commit commit message) 

  • git log –pretty=%B (Git last 10 commit msg only, no all details) 

  • git log --oneline

  •  Reset the git add file (Suppose added some file using git add<> and don’t want to add file its by-mistake or In other words, Staged -> Unstaged file) 

  • git reset (All reset) 

  • git reset <FILENAME> (Specific file name)

  •  Show code changes as per commit id:

  • git log

  • Take Commit id and paste into: git show <Commit Id>

  • Change remote branch name:

  • Git checkout <OLD_BRANCH>

  • Git branch -m <NEW_BRANCH>

  • Git push origin -u <NEW_BRANCH>

  • Abort last merge changes: git merge --abort

  • Cherry-pick:

  • git checkout -b Bugfix_DE170715_Down_Merging_to_Lower_Env origin/development

  • git cherry-pick e686f843696804e7661369a2cd72281f3ab2fb6f

  • git push origin Bugfix_DE170715_Down_Merging_to_Lower_Env

Case 1: Current Branch is 'release' and I want to code merge in 'test', which is already created in git (Issue: already add java file in current like 'stage' branch, then i move to 'test' branch. it will not allowed either commit add file in 'stage' or stash the file:

o   git stash save "message"

o   git checkout <test> : move branch from stage -> test

o   git stash list : git stash list : show stash with message .... (show stash with message)

o   git stash show -p 'stash@{0}' : show all changes in given stash

o   git stash apply 'stash@{0}'

o   Now apply, git status

Case 2: Conflict issue and apply reset by mistake then comes in initial step -> resolve issue and then again push your file from Untracked to tracked

o   git checkout .

o   git status

o   git clean -f .

o   git status

o   git pull origin development (Multiple files in green)