Showing posts with label Step wise how to create and merge new branch in GIT. Show all posts
Showing posts with label Step wise how to create and merge new branch in GIT. Show all posts

Wednesday, 8 March 2017

Step wise how to create and merge new branch in GIT

Step wise how to create and merge new branch in GIT


Git install-able files can be download from here.  Install Git on your local system.

1. Create new folder in any of your drive. For example, I created TestRepo.
      2. Go to TestRepo folder and run git bash.

Step wise how to create new branch in GIT
Step wise how to create new branch in GIT

3  Cloning a remote repo.
    Command: git clone <URL>  <where to clone>
   Where <Url> is remote repository and <where to clone> is local repository where you will do          development.
Run command: git clone //20.XXX.58.XX/XXXX
Step wise how to create new branch in GIT

4After successfully clone, you will have all remote repository files. Our project is in some folder so I run cd command, if you don’t have than no need to run cd command.

5. Viewing information about the remote repository.
Command: git remote -v –-> This commands gives the information about remote repository
         : git branch -a --> This commands gives the information about all local and remote branches.

6Create a branch according to your work. For example, I created test_new, this branch created locally, this is not available on remote repository. Now me or other developer will work on this branch.
Command: git branch test_new
Step wise how to create new branch in GIT

7. If I will run git branch, this shows currently I am working on Master branch.

Step wise how to create new branch in GIT

8Need to switch into our new branch, where we will work.


Step wise how to create new branch in GIT

9. I done some changes on my code in one file and wanted to commit. So, first I will check status what all file changed.


Step wise how to create new branch in GIT

10. Go to add into staging area.

Step wise how to create new branch in GIT

11.Now we will commit this change to our local branch “test_new”


Step wise how to create new branch in GIT

12After commit into local branch, push local branch to Remote.


Step wise how to create new branch in GIT

13Now our local branch “test_new” shold be visible on remote repository.

Step wise how to create new branch in GIT

14Now we will merge branch with master. First we will checkout local master branch.

Step wise how to create new branch in GIT

15We will pull code from master repository and will check if any other developer has been checked their code or not. If we will get as “Already up-to-date” means no other developer commit their code in master repository.
Command: git pull origin master or git pull --no-edit origin master
If you use git pull origin master and if no changes made on central repository than no editor pop will come, if any changes made on central repository than you will get editor pop, you need to press shift and : together and write q. this will exit from editor command.
Or you can use git pull --no-edit origin master, this command will not pop up editor.

Now you need to merge code with your code if any changes made on central repository code. After changes need to only commit, this will commit in master branch. 
a. If central repository have no change than you don't required to do anything.

Step wise how to create new branch in GIT
     b. If automatic merge failed, you will receive below message than you need to remove conflicts by using "git mergetool". 

Step wise how to create new branch in GIT
Step wise how to create new branch in GIT

   Click enter and one window will pop up, you need to merge your code , save and close merging        tool.
Step wise how to create new branch in GIT

     16. After successfully merge. Now we will check our code is merged with in so far.

Step wise how to create new branch in GIT

     17Above command says, our code is merged with only local master branch. Now we will merge our branch test_new with local master branch.

Step wise how to create new branch in GIT
    
    18 If you will run branch merged command, this will show all branches which has been merged and ready to push into central repository.

    
Step wise how to create new branch in GIT


    19. We will push our merged code to central repository. Now updated code available to all developer from central repository.

Step wise how to create new branch in GIT

Delete a branch 


     1.     After successfully merge and push updated code to central repository we don’t need newly created branch.
    
     2.    Check once again if your branch has been merged with master or not. If this shows than you are good to delete newly created branch.

Step wise how to create new branch in GIT

3 Delete branch locally.

Step wise how to create new branch in GIT

4. Check if branch deleted from local or not. We have only master branch. But still we have branch in remote location.

Step wise how to create new branch in GIT

5Delete branch from remote.

Step wise how to create new branch in GIT