Reputation: 823
I am very new to Git and I have done the following:
Created a new branch from master using
git checkout -b vijayv
Then, I made changes to my code, now committed the same using
git commit -a -m "UI Changes"
Well, the code changes took so long that the contents in the master branch might have changed by others.
Now I need to sync/merge the latest contents from master
and push my changes so that everybody can use it.
So can anyone tell me what steps to be followed from now on for the same?
Upvotes: 0
Views: 48
Reputation: 1024
My usual workflow would be
# Work on your branch, committing as you go...
git checkout -b vijayv
# When you're done, get the latest commits from the remote in case other people
# have updated stuff while you're working
git fetch origin
# Optional: compare your stuff to the new tip of master
git diff origin/master
# Interactively rebase - i.e. move your commits in the vijayv branch so that it
# is as if you created your branch off the tip of origin/master. You may have to
# resolve merge differences at this step.
git rebase -i origin/master
# Switch back to the master branch
git checkout master
# Get the latest changes from other people into your workspace.
git pull
# Merge your branch in. Because you did a rebase above, this will be a
# "fast-forward" merge.
git merge vijayv
# Delete your branch (assuming you never pushed it). We don't need it any more.
git branch -d vijayv
# Push your changes up to the remote
git push
I've seen this described as the "feature branch/rebase" workflow. It has the advantage of keeping a nice linear history in the repo, and the "rebase -i" step gives you the opportunity to squash commits, in other words to clean up your commits before you publish them. (A chance to hide those embarassing "fix the bug fix" commits :-) You can read about git-rebase here http://git-scm.com/docs/git-rebase .
This may look like a lot of steps but in practice it is really quick and doing an effective rebase will make you look like a git guru :-)
Upvotes: 0
Reputation: 5482
Type in git status and see what it tells you. It'll either tell you that your local version is ahead and you need to push it first, or that your online-repository is ahead and you need to pull the latest changes first.
You may want to switch to your master branch and pull the latest changes first
git checkout master
git pull origin master
Now that you have the latest version of your master branch you can merge your subbranch to it by
git merge vijayv
And that's it. Remember to push the local changes afterwards again ;)
Upvotes: 0
Reputation: 1329692
I would recommend rebasing your branch on top of (an up-to-date) master before pushing it:
git checkout vijayv
git fetch --all
git rebase origin/master
git push --force
That supposes you are working on the same repo where master is updated by others.
If that isn't the case, and you are working on a fork, then you would have in your git remote -v
one referencing the original repo (named, for instance, "upstream"):
git rebase upstream/master
git push --force
# make a pull request
Upvotes: 1