Friday, 28 December 2018

Git Commands

-------------------------------------------------------
To merge one branch into another:
-------------------------------------------------------

1) Open git bash. Navigate to the branch into which you need to merge other branch (ex: b)
$ git pull
$ git checkout a //here, a means the branch from where you are copying changes into branch b
// You will get message like - Switched to a new branch a
$ git pull
$ git checkout b
$ git merge a
$ git push origin b

--------------------------------------------------------------------------------------------------------------
To revert the changed files you added using git add command:
--------------------------------------------------------------------------------------------------------------
For example, you did: $ git add .
This would have added all changed files.
When you fire $ git status , you will see all files in green.
But if you want to remove/un-add certain files, fire this command:
$ git reset filename/pathname

--------------------------------------------------------------------------------------------------------------
To pull and push latest code:
--------------------------------------------------------------------------------------------------------------
$ git pull
$ git add filename OR git add .
$ git status //to check which files will be committed
$ git commit -m "comments"
$ git push

---------------------------------------------------------------
To rename phase-2 branch to new name 'phase-3'
---------------------------------------------------------------

$ git branch -m phase-2 phase-3


$ git push origin :phase-2 phase-3


-------------------------------------------
To merge phase-2 branch with master branch
-------------------------------------------
Switch to Master branch with following command:

$ git checkout master

Merging/Pushing phase-2 branch code to master branch:

$ git merge feature/phase-2

To push this change:

$ git push

--------------------------------------------------------------------------------------
Create new branch "phase-4" from master branch:
--------------------------------------------------------------------------------------
Go to master branch and run:
$git checkout -b phase-4
// This above command with -b will create a new branch if not existing; without -b it will just switch to an existing branch

$ git push

NOTE: IF you get below error on firing 'git push' command, then fire the third command mentioned below.
fatal: The current branch phase-4 has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin phase-4


$ git push --set-upstream origin phase-4


No comments:

Post a Comment