Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull after local commit

Tags:

git

git-bash

I am new to git. I have a few local commits but I want to pull the latest code from the repository and don't yet want to push mine. However git pull, creates unnecessary merges. What is the right way to do this i.e update your local repository without losing the changes.

like image 242
Sesha S Avatar asked Feb 23 '12 03:02

Sesha S


People also ask

Can we do git pull after a commit?

If you have uncommitted changes, the merge part of the git pull command will fail and your local branch will be untouched. Thus, you should always commit your changes in a branch before pulling new commits from a remote repository.

How do I pull a commit locally?

If you want to bring that specific COMMIT_ID to your local branch, you may either use git-cherry-pick to bring only that commit over, or git-merge to bring all changes up to that commit to your local branch.

Does git pull overwrite local commits?

git pull --force it feels like it would help to overwrite local changes. instead, it fetches forcefully but does not merge forcefully ( git pull --force = git fetch --force + git merge ). Like git push, git fetch allows us to specify which local and remote branch we want to work on.

Will git pull remove my local changes?

The reason for error messages like these is rather simple: you have local changes that would be overwritten by the incoming new changes that a "git pull" would bring in. For obvious safety reasons, Git will never simply overwrite your changes.


1 Answers

The tool you are looking for is git rebase, though you should look at the documentation about that before you start using it. It is also generally good practice to do development in a local branch to reduce the overhead of this sort of operation.

When you are comfortable, you can use git pull --rebase to use rebase rather than merge to resolve differences after the pull -- but, do read the docs first, because this can lose data or cause headaches if misused. It is a useful but dangerous tool.

like image 89
Daniel Pittman Avatar answered Oct 04 '22 04:10

Daniel Pittman