... | @@ -15,7 +15,7 @@ |
... | @@ -15,7 +15,7 @@ |
|
# Pulling from git when your local version has been modified
|
|
# Pulling from git when your local version has been modified
|
|
Here's a typical scenario:
|
|
Here's a typical scenario:
|
|
``` console
|
|
``` console
|
|
$ git checkout <branch>
|
|
user@host:~/repo/blocks$ git checkout <branch>
|
|
(git tells you it won't check out <branch> because you have changes you haven't committed)
|
|
(git tells you it won't check out <branch> because you have changes you haven't committed)
|
|
```
|
|
```
|
|
|
|
|
... | @@ -26,29 +26,29 @@ You now have three choices: |
... | @@ -26,29 +26,29 @@ You now have three choices: |
|
|
|
|
|
In case 1, you do:
|
|
In case 1, you do:
|
|
``` console
|
|
``` console
|
|
$ git commit -am "<commit message>"
|
|
user@host:~/repo/blocks$ git commit -am "<commit message>"
|
|
$ git push
|
|
user@host:~/repo/blocks$ git push
|
|
```
|
|
```
|
|
|
|
|
|
In case 2, you do:
|
|
In case 2, you do:
|
|
``` console
|
|
``` console
|
|
$ git reset --hard HEAD
|
|
user@host:~/repo/blocks$ git reset --hard HEAD
|
|
```
|
|
```
|
|
|
|
|
|
In case 3, you do:
|
|
In case 3, you do:
|
|
``` console
|
|
``` console
|
|
$ git stash
|
|
user@host:~/repo/blocks$ git stash
|
|
```
|
|
```
|
|
|
|
|
|
After doing any of these three things you should be able to check out the branch you want without any issues.
|
|
After doing any of these three things you should be able to check out the branch you want without any issues.
|
|
``` console
|
|
``` console
|
|
$ git checkout <branch>
|
|
user@host:~/repo/blocks$ git checkout <branch>
|
|
```
|
|
```
|
|
|
|
|
|
**BONUS:** Let's assume you were in case 3 and you stashed the changes, then checked out a working branch. Now you want to switch back to master and get back the changes you made. Here's what you do:
|
|
**BONUS:** Let's assume you were in case 3 and you stashed the changes, then checked out a working branch. Now you want to switch back to master and get back the changes you made. Here's what you do:
|
|
``` console
|
|
``` console
|
|
$ git checkout master
|
|
user@host:~/repo/blocks$ git checkout master
|
|
$ git stash pop
|
|
user@host:~/repo/blocks$ git stash pop
|
|
```
|
|
```
|
|
|
|
|
|
For more information, see Git's official documentation for the stash command:
|
|
For more information, see Git's official documentation for the stash command:
|
... | | ... | |