[GIT] Create Branches, commit and Merge

This is part 2.....if you want to check out part 1 go to...Part 1 Create local and Remote Repos..

as I told you on part 1 I'm using this tutorial parallel  to the QTableView simple application tutorial to teach you some basics stuffs about GIT and also GIT on Qt.....so lets continue


because I want to start adding the logic behind all the GUI I have created, I think it will be good to add a new branch to my current project, and when all that new stuff is ready and tested I can merge it to the master branch...

for the ones who doesn't know, a branch on GIT lets you work on a copy of your primary development line, add all the code you like to it, remove, improve...everything to can imagine, and then if everything works as expected, merge all that code to your primary development line or master branch, as you might imagine this is very useful...

after check bracnh




so ill teach you how to create a branch on your local and remote repository, commit your changes to that branch and then merge it....

first of all you have to cd to your projects folder...using the GIT CMD

img1



then write.. git checkout -b <name> on the console, where <name> is the name of the branch you are going to create... NOTE: it is important that you commit your changes before creating a new branch.

img2


I can use git branch to create a new branch and then git checkout to start working on that branch but git checkout -b does it all at once....

if you hit git status, you can see the branch you are currently working on

img3


because I'm working this code on Qt, I can see next to my projects name, the branch where I'm working on...

img4



after creating a local branch you can also create one your remote repository so that you can push the code to it, to do this you have to type "git push --set-upstream <repo> <branch>" where <repo> is the name of your remote repository and <branch> is the name of the branch you have created..


img5

so right know you have created a local branch and have push it to the remote repository.....by the way I have changed to GIT BASH

after some editions I can commit my changes....


img6


as you can see I have to commit some files and also add the database.db file so that can be tracked
for this I run "git add database.db", I'm going to commit each individual file with the changes I've made...


but what if I forget what changed did I made to it??......then you can run "git diff" to see whats changes has been made to each individual file, or run "git difftool" to inspect one by one.....but because I'm working this along with Qt I can use the tool it provides for the integration with git...

img7




there if I compare for example mainwindow.cpp I can see that I have added 19 new lines (green)..

img8


from that menu I can even commit my changes......shortcut for this is (Alt+G then Alt+C)..

img9

img10


after I commit all my changes I can push all that to my remote branch using git push from the Qt menu or using the command on Git Bash or Git Cmd

img11


after I have commit and pushed all those changes, and tested my project again...I think I can merge that new features to my master branch.....to do so first is gut to run "git status" to check the current status of the branch I'm working on...

img12


if everything is ok I can switch to my master branch an then merge......I can switch to my master branch typing "git checkout master".....then ill run "git merge <branch>" where <branch> is the name of the branch you are going to merge....

img13


then ill push those changes to my remote repository by running "git push <repository> <branch>"........

if I run "git branch" I can see the branches currently existing......because I don't need that ppalcode branch anymore I can run "git branch -d <branch>" to delete it...

img14


if you want to delete also your remote branch you can run "git push -d <repository> <branch>.....

img15


you can check that both local and remote branch have been deleted and also your code has been merged....

so this is the end for this tutorial, I hope that will be useful for someone......


SHARE

Daniel Sanin

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment