Kallel Omar
Kallel Omar

Reputation: 1218

git: better way in commit/push

when I was working on projects that uses the control system git, each time I want to commit then push my modifs I have ofcourse to git pull before. But the problems that I meet is that in many times git prohibits me to pull because I should before commit my local changes. What I used to do is that I have an other clean git repo where I don't modify it directly, but when I need I use it to git pull then merge my modifs to it using meld, from the other repo where I work. But I think that this way is not the best and lose a lot of time, it's time to optimize it. What I'm thinking to do is that I create an other local branch "work_branch" and commit my modifs to it locally then merge commits from "work_branch" to "master" then push in master after the pull. So the scenario should be like that:

git branch work_branch
git checkout work_branch
#modify in branch work_branch
git commit
git add <files list>
git commit -m "fixes branch work" #local commit
gitk ==> get the id of "fixes branch work" commit (example: 5b099287c229e16c24bfcdbfd6fba384cfe165e6)
git checkout master
git pull
git cherry-pick 5b099287c229e16c24bfcdbfd6fba384cfe165e6 #merge "fixes branch work" commit from work_branch to master branch
git push

The problem that I met is after the third step (#modify in branch work_branch), each modif in the branch work_branch is viewed by the master branch, but what I want is that master branch can see from work_branch only the merged commit after git cherry-pick command. Is there a way to improve my solution. Or is there an other good way to optimize working with git.

Upvotes: 0

Views: 86

Answers (1)

clamentjohn
clamentjohn

Reputation: 3977

Git is a VCS (Version Control System).
How git's generally used
enter image description here

A feature branch is made where you need to make changes, while work goes on master branch (eg bug fixes) and when feature branch is ready to be added into the master (ie you're ready to add the feature to your master code base) you git merge <feature branch>

How you're using it
enter image description here

Its a bit messy. Try following a regular method where you commit every change you need in your code and in the end merge it with the master.

Another suggestion, use git rebase. (Google it, there are many explaining it visually). Also google git fetch then git merge origin/master master method to reflect changes of master into your working repo. Use rebase, so as to see only one commit (not commit + merge commit) on your repo

Basically, go through a git tutorial. Its easy and you'll understand the basics in less than 10 minutes.

Upvotes: 1

Related Questions