Git and Github Tutorial - The Branch - Part 9

Hi, Today in iThePro we will learn how to use Git and how to use with Github to build software and develop it. In this part we will see the Branch.


Branching Overview:
Branch are easy to work with.
Use it to try new ideas:
-> because if you have a idea and if it does work out, then you can fold those change back into the master branch through a process we call merging.

 Viewing and creating branches:
git branch
This will give us a list of the branches we have in our working directory.
 git branch <new-branch>
This will create a new branch.

Switching branch:
git checkout <new-branch>
 This will switch to the <new-branch> and make our directory look like the branch we chose it.
git checkout -b <new-branch>
 This will create and switch in the same time to the new branch.

Switching branch with uncommitted changes:
we prefer to do not leave the branch unless it's clear (git status) .
-> No problems with untracked files.

Renaming Branch:
git branch -m <new-branch> <new-branch2>
 This will rename the <new-branch> to <new-branch2>

Deleting branch:
git branch -d <branch-to-delete>
 This will delete <branch-to-delete>.

Comparing branches:
git diff <branch1>..<branch2>
 This will compare the difference between the <branch1> and <branch2>

Configuring the command prompt to show the branch:
1 - edit the .bashrc file on the user directory
2 - add this $(__git_ps1) "(%s)") in the end of the variable PS1
3 - save and close

See the Git and Github Tutorials.


Author

OUSSAMA AMRI

Oussama Amri 21 years, security professional from Tunisia. Lover of computer science especially programming and secuirty. Follow me On :

Popular Posts

iThePro.com. Powered by Blogger.