How to Commit your code to a branch in GIT

How to Commit your code to a branch in GIT

GIT provides a lot of features, we can create branches and we can push the code to a specific branch. Following are the steps to push a code to a specific branch with a new branch

1. Go to your working directory

2. Create a new local branch as following
>> git branch
Ex: git branch test_branch

3. Switched to branch
>> git checkout
Ex: git checkout test_branch

Now you are in test_branch, When you create a new branch in GIT it will create a new branch with the existing code.

4. Now update/modify your code in test_branch, Once you are done with the changes do following

5. git add -A ( to add files)

6. git status ( to check the status of changed files )

7. git commit -m ‘commit message’ (to commit the files in test_branch)

8. gitk (to view the changes of your files )

8. git checkout master ( to switch to the master branch )

9. git pull origin master ( Get the latest code from origin master )

9. Merge local branch i.e. ‘test_branch’ changes with latest master code by using the following command.
>> git merge test_branch

If you will get merge conflicts, then fix it and commit the code.

Now you are ready to push the code into the branch

10. Push your local change into dev review branch by using following command
>> git push origin master::<review_branch>/<firstname.lastname>/<remotebranch>
Ex: git push origin master:review/laxma.reddy/brnach_for_test_review

Comments 1

Your email address will not be published. Required fields are marked *

log in

Become a part of our community!

reset password

Back to
log in