Skip to content

Instantly share code, notes, and snippets.

@y56
Created July 14, 2020 09:56
Show Gist options
  • Save y56/d22bd742ce2266e55e027f39cc7fefef to your computer and use it in GitHub Desktop.
Save y56/d22bd742ce2266e55e027f39cc7fefef to your computer and use it in GitHub Desktop.
Git - opening and editing files from other branches
https://stackoverflow.com/questions/38016277/git-opening-and-editing-files-from-other-branches
There two ways you can do this:
Commit the changes in alt branch and then do git checkout master.
If you do not want to commit then do git stash in alt branch and then go to master by doing this: git checkout master. Later once you have done the testing in master, checkout to alt and do git stash apply(this would reapply the changes to alt branch).
Each time you do git stash it creates a list of changes, which can be checked by git stash list. Each item will have an index number to it starting from 0. So if you stash more than once you can reapply a particular stash like this: git stash apply @stash{<index_no>}.
You can read more on git stash here.
Stack Overflow
Products
Search…
y56
13
, 13 reputation
●33 bronze badges
Home
PUBLIC
Stack Overflow
Tags
Users
FIND A JOB
Jobs
Companies
TEAMS
What’s this?
Free 30 Day Trial
Git - opening and editing files from other branches
Ask Question
Asked 4 years ago
Active 4 years ago
Viewed 391 times
0
I am working on a project with two git branches - master and alt. I have been working on the alt branch for a few days to try some things out, but now I want to switch back to working on the master branch to test a few things out there (without deleting alt). Of course, I know about using checkout to switch between the branches, but what I actually need is the ability to open and edit the master branch as it was left a few days ago. When I git checkout master and open the project in Sublime Text, the version of the project that I see is the alt version.
How does one not only checkout a branch but open and edit the project as it was last left on that branch?
git
share edit follow
asked Jun 24 '16 at 14:51
skwidbreth
4,83433 gold badges3838 silver badges7676 bronze badges
1
I would expect Git to not let you checkout the master branch if you have done some work in alt. Are you sure you really switched branches? – Tim Biegeleisen Jun 24 '16 at 14:53
add a comment
2 Answers
Active
Oldest
Votes
2
if you use git checkout master and then click into sublime text, it will automatically show the updated version. Your question answers itself, as git checkout is the only way to do the required task.
Are you using any sublime packages to enhance git?
share edit follow
answered Jun 24 '16 at 14:54
Vincent Rodomista
59144 silver badges1717 bronze badges
You are correct - my apologies, Sublime Text does do this automatically. My mistake was that I had unsaved changes that hadn't been committed to the alt branch. – skwidbreth Jun 24 '16 at 15:20
add a comment
3
There two ways you can do this:
Commit the changes in alt branch and then do git checkout master.
If you do not want to commit then do git stash in alt branch and then go to master by doing this: git checkout master. Later once you have done the testing in master, checkout to alt and do git stash apply(this would reapply the changes to alt branch).
Each time you do git stash it creates a list of changes, which can be checked by git stash list. Each item will have an index number to it starting from 0. So if you stash more than once you can reapply a particular stash like this: git stash apply @stash{<index_no>}.
You can read more on git stash here.
share edit follow
edited Jun 24 '16 at 15:03
answered Jun 24 '16 at 14:58
sahil
3,07011 gold badge1515 silver badges3737 bronze badges
1
Thank you, that is very helpful. I realize that I had made a mistake, though, which is that I had uncommitted changes on the alt branch. Once I committed them and switched back to master, Sublime Text opened the master branch files. – skwidbreth Jun 24 '16 at 15:21
add a comment
Your Answer
Links Images Styling/Headers Lists Blockquotes Code HTMLAdvanced help
Community wiki
Post Your Answer
Not the answer you're looking for? Browse other questions tagged git or ask your own question.
The Overflow Blog
The Overflow #29: Checkboxland
Tales from documentation: Write for your dumbest user
Upcoming Events
2020 Community Moderator Election
ends in 7 days
Featured on Meta
Feedback post: New moderator reinstatement and appeal process revisions
The new moderator agreement is now live for moderators to accept across the…
Allow bountied questions to be closed by regular users
2020 Community Moderator Election - Questionnaire
Related
Hot Network Questions
Contradictions of explanations for the speed of light
Pascal's tree-angle
Compression Library for C using Huffman Coding
Access to journals during pandemic
Who is the lady on the image?
Could blue flames arise within the hull of a burning ship?
How to store persistent values in STM32F407VGT6 embedded microcontroller?
How should I deal with a subordinate who is distracted and not performing well?
How can I easily keep track of my landing count during pattern work?
Can you combine an Artificer's Enhanced weapon infusion with a +3 magic weapon?
Elementary inequality generalizing convexity of a function on a segment
A player rolls several 20-sided dice, takes the lowest value, ignores the rest. What is the probability of this value being at least 7?
What is the Subspace Dimension?
Panoramas with a Ball Head
I am a computer science student doing an internship but isn't getting to work with any code / any developers. Is this normal?
Unable to fully maximize Terminal window
Time-saving (technology) tricks for writing papers
Interaction between an Intellect Devourer and a Simulacrum
more hot questions
Question feed
STACK OVERFLOW
Questions
Jobs
Developer Jobs Directory
Salary Calculator
Help
Mobile
Disable Responsiveness
PRODUCTS
Teams
Talent
Advertising
Enterprise
COMPANY
About
Press
Work Here
Legal
Privacy Policy
Contact Us
STACK EXCHANGE
NETWORK
Technology
Life / Arts
Culture / Recreation
Science
Other
Blog
Facebook
Twitter
LinkedIn
Instagram
site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2020.7.13.37214
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment