Skip to content

Instantly share code, notes, and snippets.

@jinnabaalu
Last active April 27, 2017 17:39
Show Gist options
  • Save jinnabaalu/ffebd2e7d81560f720210623c01ddc65 to your computer and use it in GitHub Desktop.
Save jinnabaalu/ffebd2e7d81560f720210623c01ddc65 to your computer and use it in GitHub Desktop.
Simple steps to create a branch and merge the branch to master
---------------------------------------------------------------------------------------------------------------------
| $ git checkout master
| $ git checkout -b jinnaBalu/Sample ////created branch with the name jinnaBalu/Sample
(Naming convension to follow but not mandatory jinnaBalu is github user name and Sample is branch name)
| $ git push --set-upstream origin jinnabalu/Sample ////To push the current branch and set the remote as upstream
Ready to work on your branch
As you done with the changes and push your code to remote branch, do the following steps
| $ git status //// gives you the modified and created files
| $ git add --all //// add all the files to commit
| $ git commit -am "<mesage that you have done with this branch>"
| $ git push //// pushed your changes to your branch without changing master
If we are ok with the current branch changes we can merge our chanages to the master
| $ git checkout master
| $ git merge --no-ff origin/jinnabalu/Sample ///// all your branch changes are in master now
For detailed explanation please follow as below
Check the status of the current branch
----------------------------------------------------------------------------------------------------
$ git status
(make sure you are the correct branch before you commit or push)
If you find any changes like modified or created ones
Add your changed files for commit using
----------------------------------------------------------------------------------------------------
$ git add --all
Commit changes(you can do the "git status" to understand the status of the add)
----------------------------------------------------------------------------------------------------
$ git commit -am "commit message" (-a - all, m - message)
Push change sto the remote branch
---------------------------------------------------------------------------------------------------
$ git push (by default it pushes to the remote branch)
OR
$ git push origin <BranchName>
$ git push origin jinnabalu/Sample (jinnabalu/Sample is branh name)
_______________________________________________________________________________________________________
--------------------------- Branching --------------------------------------------------------------
_______________________________________________________________________________________________________
Suppose I have master branch
(Good practice is to have two branches DEVELOP and MASTER)
Checkout to branch
-----------------------------------------------------------------------------------------------------
$ git checkout master (if you are on the same branch please ignore, no harm if you do)
Create a branch from matser
-----------------------------------------------------------------------------------------------------
$ git checkot -b <Branch-Name> (being in the master branch)
Important Note : Branch naming convension should be in camelCase, PascalCase, snake_case but not mandatory
Example : git checkout jinnabalu/sampleBranch
This command will do two steps here
1. Create the branch from the master with the name jinnabalu/sampleBranch
2. It'll checkout to the Brnahc created
Now you are in "jinnabalu/sampleBranch" branch
Push branch to the Origin to set local branch to upstream
--------------------------------------------------------------------------------------------------------
$ git push --set-upstream origin <BranchName>
Example : git push --set-upstream origin jinnabalu/sampleBranch
OR
$ git push
This step explains you what you need to do
fatal: The current branch jinnabalu/sampleBranch has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin jinnabalu/sampleBranch (copy this command and paste and enter)
This step will push your local branch to origin, now you are ready to work on your branch
As you done with the changes follow this steps as above
----------------------------------------------------------------------------------------------------
$ git status (optional)
$ git add --all
$ git status (optional)
$ git commit -am "<changes related to my current work on this branch>"
$ git status (optional)
$ git push
Done you changes are commited and pushed to your branch without changing master branch
As you done with the push, you need to merge your branch to the master
-------------------------------------------------------------------------------------------------------
$ git checkout master
$ git merge --no-ff origin/jinnabalu/sampleBranch
Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment