Friday, February 22, 2019

Git Bash

Git Bash
----------
- Git Clone project (Get the project into your local)
  git clone <git_url>
 
- Command will show the git master (origin)
    git branch

- Command will fetch everything from the master
    git fetch

- Checkout the branch / switch to existing branch
    git checkout <branch_name>

- Revert a single file (Complete revert like SVN)
   git checkout <file_name_includes_path>

 - Creating a new branch 'branch_name'
    git checkout -b <branch_name>   

- Merge specific commit id (Advantage it pushes the same commit version over new branch)
   git cherry-pick <218c4e40654a2d53fdaf3f1b47a58867f432b8ed>

- Changes which is in local and not in remote
   git log --branches --not --remotes

- Pull the changes into local from git
  git pull origin <branch_name>

- Hard reset from local cahanges
  git reset --hard HEAD^

- Unstagged a staged file
  git reset HEAD .

- Add .gitignore file
  touch .gitignore

- Push local changes file into staged
  git add <FileName>

- Commit the file into git (From unstagged to stagged)
  git commit -m 'commit message' <filename>

  - Push the changes into remote branch from local
  git push -u origin <branch_name>

- Show the differences in local
   git diff .

- Git stash of switching between branches (store the files temperoarty storage and switch to branch (new)). It will help you to store and switch between branches
  git stash

- Stashing untracked files (save)
$ git stash -u or $ git stash --include-untracked

- save specific file file specific messages. -u untracked files to push untracked files.
git stash push -u -m "<your message>" <filename_includes_path> [<filename_includes_path>]

- Git show the stash files
git stash show stash@{1}

- Git stash show the stash files diff
git stash show -p stash@{1}

- see the `git stash list` once you see choose and apply specific. --index will stage the file in the same location where you kept earlier
git stash apply stash@{1} --index 

- Popping your stash removes the changes from your stash and reapplies the last saved state
git stash pop

- Delete from git stash (storage) the latest
git stash drop [stash_id]

- Remove all from stash
git stash clear

How to Merge:
--------------
git checkout <working_branch>
git pull origin <working_branch>
git checkout <master_branch_source_branch>
git pull origin <master_branch_source_branch>
git merge <working_branch_which_you_want_to_merge_in_source>
    (Resolve the conflicts if any)
    vi <file_name>
git add <resolved_conflict_files>
git commit -m "" <resolved_conflict_files>
git push -u origin <master_branch_source_branch>


// Below script tag for SyntaxHighLighter