0

Right now I have locally a credential file that I use locally to test my changes.

set_env.py defines environment variables that I use to log in a distant app

As I don't want to actually push the credentials, I pushed a dummy file which basically does nothing (as the environment variables are supposed to be already defined on the test server for example).

However, since I have a dummy file pushed to my branch, set_env.py is considered staged and I cannot change branches

git checkout other_branch

error: Your local changes to the following files would be overwritten by checkout: config/set_env.py Please, commit your changes or stash them before you can switch branches. Aborting 

A solution would simply to stash this file every time I want to switch branches (assuming I have no other modified staged and non-commited file)

git stash git checkout other_branch git stash apply 

However it becomes cumberstone to have to type 3 commands each time I want to change the branch I'm working on. Is there a way to tell git to consider this file as unstaged from now on ? (without deleting the file on the next commit)

Edit: @phd answer seems the most straightforward, however it does only work if I don't have any other staged uncommited file. Is there a solution where I could do what I want and still stash other files ?

Cheers

1 Answer 1

1

Create an alias:

git config alias.stco "!f() { git stash && git checkout "$@" && git stash apply ; }; f" 

Usage:

git stco other_branch 

PS. stco for "stash and checkout".

Sign up to request clarification or add additional context in comments.

1 Comment

This seem to work, however it is only possible if I don't have any other staged uncommited file in my branch

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.