Reputation: 488
$git branch stable development
I have properties file which has password for Database connection, now I had to change the properties file (say xyz.properties) for password. So that i can use on local server. and added this file path into .gitignore and $git update-index --assume-unchanged xyz.properties
$git status On branch stable Your branch is up-to-date with 'origin/stable'. nothing to commit, working directory clean
Now i wanted to change ...branch to development $git checkout development
error: Your local changes to the following files would be overwritten by checkout: .gitignore x/y/z/xyz.properties
Please, commit your changes or stash them before you can switch branches. Aborting
Now I want to change branch to development and make branch and work on them.
So how can i achieve this task...please help me out. Thanks in Advance
Edit when i tried $git stash No local changes to save
Note: I need to use local server from every branch , which required my xyz.properties files to be modified because my local db has different password then repository.
Upvotes: 4
Views: 7018
Reputation: 488
So the issue is to modify the xyz.properties file as per your environment need, so if you try to put it into .gitignore file, it will not work, because xyz.properties is tracked file and synced with repository.so now there is two things can be done.
1> untrack the xyz.properties file and put them into .gitignore, but it will not sync with repository, and you cannot share a basic properties file which is beneficial for other programmers who are using same project and requires the repository and properties file.
2> make a xyz.properties.example in repo that will be shared and synced by repo and will be available to everyone who are using the same project. Now put xyz.propertes into .gitignore , who ever is using will create local file and copy the contents from xyz.properties.example , and obviously that file will remain untracked and ignored.
Hence you can achieve your task...better way.
Upvotes: 1
Reputation: 560
Make sure stash it and switch another branch
git stash
git checkout development
Now you can work at branch development
when you checkout back, you need restore your workplace and delete stash
git checkout last_branch
git stash pop
Notice: you can check out your stash status by
git stash list
if it returns nothing. Your workplace is clean. Now you can work at last_branch.
Upvotes: 1