Git : adding, merging and deleting branches

Creating branch and pushing changes.

First clone a repository to your local machine.

$ git clone test@<IP>:repo.git

You can see all branches using:

$ git branch

To create and switch to a new branch:

$ git checkout -b <mybranch>

This is shorthand for

$ git branch <mybranch>
$ git checkout <mybranch>

Now make changes to any file and add it.

$ git add .

Commit the changes.

$ git commit -m “commit_name”

Push changes to branch now.

$ git push origin <mybranch>

Updating and merging changes.

To update your local repository to the newest commit and to fetch and merge remote changes.

$ git pull # pulling details of new branch

$ git checkout <mybranch> # switching to new branch to see files

$ git merge origin/<mybranch> # merging files in branch to master

$ git add .

$ git commit -m <commit_name>

$ git push origin master

Deleting branch.

$ git checkout master # Switch to master first

$ git branch -d <mybranch> # Delete the branch

Leave a Reply

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