I am using github and I have the following question, I have a master branch and I created a new branch out of master by doing
Git branch {branchname"
Git checkout {branchname}.
Now I need to edit some settings file , should I edit this file from my new branch or the Master? If I edit it from the new branch, then each time I create a new branch for different projects, then I should be modifying this settings fileā¦but at the same time if I edit it by being on master branch, then when I merge/update master branch later, then I would loose the changes. Can someone please clarify the best way to handle this? If I have to do it from Master, then how I can stash it as I never push anything from master branch.
it depends what you want. If you want the new settings to be available everywhere, you need to modify the file in master, check it in, then rebase any existing branches to get the settings.
If you only want the changes in the other branch, make them there. If you ever merge the other branch back into master, then master will then have them.
Related
I want to know what is the best way to use the command: Merge branch name into current branch
What i am doing (Let us suppose I want to merge master into develop):
I checkout to the master branch and pull all the recent changes.
Then I go back to the develop branch.
I right click on the master branch and click Merge branch name into current branch.
And the master branch will merge into the develop branch.
Is this correct?
Your methodology looks correct.
If you are not seeing any changes tothe branch you are merging into - then it is likely this branch is already up-to-date with the branch merged into it.
You can also look up the following references on the Merge comnmand you are using:
Git Tutorial (Beginner): Using GitLab & Source Tree
I was working on a branch of my Bitbucket repo (lets call it "frontend-dev"), which has now been merged with the master branch. I would like to branch again to make further changes, without creating a new branch. How do I branch and get back onto "frontend-dev".
I am using Sourcetree to manage version control.
Normally merging to master does not close or delete the branch. If there are changes in master since the merge from "frontend-dev", you can merge back to "frontend-dev". Either way, you can then simply switch your working copy to "frontend-dev" and continue developing.
Another question discusses what to do when you have closed or deleted the branch: Restore Merged Branch in Bitbucket Repo
I am new to managing code revisions and need guidance on how to merge to code sets. I have a MASTER branch with my latest UI and I have a branch called "Feature-A" with lots of Django additions + template additions to the previous UI files.
Since I am new to Github, I want to take the safest approach incase I need to revert mistakes. Should I make a new brach of master and merge Feature-A into that branch or should I merge Feature-A directly into the MASTER?
Since you're new, I would say the best approach would be to create another branch (clone of master branch) and then merge feature A into that, and see if it works. If not, keep testing feature A to make it compatible. If it works, great! Just remove that extra branch and merge feature A into the master.
I.e.,
git checkout master
Then, create a new branch (git checkout -b 'featuretest')
Now, git branch shows
* master
* featureA
* featuretest
Then, do git checkout featuretest, and git merge featureA to merge it.
If the feature works, great! Remove the branch (git checkout master; git branch -d featuretest)
and do it for real (git merge featureA)
If the feature doesn't work, go back to the feature branch (git checkout feature) and keep testing.
I am not sure what github is telling me to do here. I only have one branch, which is master.
[screenshot]1
Master is default branch. Your main branch. It automatically comes when you open a repository. If you open another branch, it means that you have master and one more.
I've been using GIT for a couple of weeks now and trying to understand how to switch branches without commiting files. This is what I have done.
Cloned a git repository and have a local master branch.
Created a new local branch (Branch2) which is based on a remote branch.
Made changes to 2 files in the master branch.
What I want to do now is switch from master to Branch2.
The changes I made to the master branch are for local dev purposes only and should never be committed.
But when I try to do this in eclipse (i.e I double click on the local branch I try to switch to) it keeps telling me that there are uncommitted changes and I need to commit, stash or reset.
Can anyone tell me how i can make a change to a local file and have git ignore this change so that I don't get prompted with this message?
Note: if you need to stash a work in progress from Eclipse, Egit now supports stash:
Have a look at git stash. Stash allows you to store uncommitted changes.
Option 1
git stash
git checkout -b Branch2
Your changes will be stored in git (locally). When you want to re-apply those changes, you will do git stash pop and it will apply those changes for you.
Option 2
git stash
git stash branch temporarybranch
This will take your uncommitted changes to a new branch and keep them there for you. Compared to the previous option, this allows you to keep these branches on the server by pushing this new branch.
Hope it helps
If you don't want the changes to be ever made public you should just commit them in your own feature branch and not on the master branch.
You can create a new branch, give it a name that reflects the changes, maybe prefix is with something like "experimental-" and then commit to that branch before switching to your other branch.
You can use git stash to stash your changes, or use git stash to commit them directly to a new branch as mentioned by Ege Akpinar.