This post is going to be an example
that my tutor in Pernix showed me about how is that git branching,
merge and rebase work.
Basically, this is used when there is
more than one person working in a project, and everybody have to work
in different things. What I'm going to show is that I have a
repository with some files so i'm going to do 2 “copies” of that
repository in which I will work, and make different changes,then I
will merge everything in the master branch and delete the branches
I've created. What is the idea with this, since there are so much
people working on the same files, probably the all of them are not
going to have the latest release or latest changes, that a coworker
did, so with this we are able to have everything up to date, without
the problem of having different things in the files that we are
having as base.
Let's start:
- First we are going to see the branches that we have, that can be done with the command: git branch -a.
- Now I'm going to do a branch where I'm going to do some changes to the files. The creation of the branch is done with the command git checkout -b BranchTest1
- After that we type again the command git branch -a and and it should appear the list of repositories we have.
- The command to change the branch in which we are is git checkout master (in this case master is the name of the branch but if we are on the master we also can say git checkout BranchTest1), so let's change to the master branch
- Then we make a pull rebase to be sure that everything is up to date git pull --rebase origin master
- Now we need to be in the BranchTest1: git checkout BranchTest1
- Let's make a change in a file
- We need to verify the status of the files in the repository so we do it with the command git status, in my case that says that I modified a file
- Right now we need to add the file modified with the next commands in the order that they appear a) git add . b) git commit -m "primer commit branching" c) git push origin BranchTest1
- Pass to the master branch git checkout master
- Now create a new branch git checkout -b BranchTest2
- Modify a file and add it to git as in step 9
- Let's pass to master branch git checkout master
- Now we are going to merge the changes in BranchTest2 git merge BranchTest2
- Then we push it in the master branch: git push origin master
- After that we change to BranchTest1 git checkout BranchTest1
- And now we do a pull –rebase ,and here is the thing we were searching , we're gonna have a conflict git pull --rebase origin master
- Now go to the file that is showing us the conflict and solved it,the editor will show you where is the conflict
- Then add the file git add <Filename>
- Also we need to do git pull origin BranchTest1
- After we do git push origin BranchTest1
- Finally we do git pull --rebase origin master, git checkout master, git merge BranchTest1, git push origin master
- And delete the branches git branch -d BranchTest1 , git branch -d BranchTest2 git push origin :BranchTest1 git push origin :BranchTest2
No hay comentarios:
Publicar un comentario