Sunday, 26 March 2017

Git Commands Part 2 - Simple Commit, Pull and Push - Master/Branches

     With continuation to the post


6.     Commit the Changes to the local repository -m indicates the message content on the “message” which is used for the future references & Push the same to the remote branch

git commit -m "employee model class and method added"
git push origin branch0 

7.     Every time we need to keep our branch Ahead of master not behind, because it might have conflicts with other branch code, so we need to resolve and keep it has updated one. (This conflicts and resolve feature will be explained in the next post)

If the remote branch seems to be behind, we need to update the local
repository equivalent to that code.

Go to your local repository first we see how to take an update to the master.

git checkout master
git pull

The master branch will be updated.

Checkout the other branch, get the updated code if anything is need to be get it from the remote branch.

git checkout branch0
git pull
git push origin branch0

Get the updated code from the remote master and push the code to remote branch

git checkout branch0
git pull origin master
git push origin branch0

Same the we can get the updated code from another branch as well

git checkout branch0
git pull origin branch1
git push origin branch0

Git Commands Part 1 - Create, Rename and Delete Branches

This post will help you to play around the Git Commands for creating a branch in both local and remote repository, also guides to rename and deleting the branches.

1.      Create a Branch: Creating a branch in local machine and push that to the remote repository.

Initiate to create a branch & checkout i.e. switches to make use of the branch, the branch has been available in the local 

git branch branch1    
git checkout branch1  
(or)
git checkout -b branch1  

To push this in to the remote use the below command.
git push origin branch1

In case the branch is already created in remote either on Bitbucket or GitHub Portal or any, so now we are need to fetch that & checkout the same into our local.

git fetch origin branch2  
git checkout branch2   
(or)
git fetch && git checkout branch2

2.      Renaming a Branch: We are in the branch2, but want to rename the branch1 as branch0, the below command will reflect on local only, not impact on the remote

git checkout branch1
git branch -m branch0
   
The below command will rename the branch and not necessary the user to
be in the branch which is intended to rename. $git branch -m
<Old Name> to <New Name>

git branch -m branch1 branch0

To reflect the above changes to the remote. 
$git push origin :<old_name> <new_name>

git push origin :branch1 branch0

3.      View the list of branches:
git branch

4.      To-do a self-check, which branch is currently we are working on
git status

5.      Delete a Branch: The below command will help to delete the branch from local.
git branch -d branch0

To delete the same from remote.
git push origin --delete branch0

*To delete the branch, we need not to be in that deleting branch.

          Continue to read Part-2