I am using Bitbucket in my project. When I am cloning the code on my local machine with my branch URL I am getting the updated code of my branch and unable to see the changes in the other branches. How to clone the updated code from all branches in Bitbucket?
First check which branch you're on and if you have already checked out the master branch:
git branch
You should see something like, although the names will probably be different:
dev
master
* test
Switch to the master branch. If master WAS NOT listed in the previous step run the following:
git checkout -b master origin/master
If master WAS listed just run:
git checkout master
You will now be on the master branch. Now do a git pull for the latest updates.
Related
I created a new Rails app and pushed the code to Github directly from master (first commit in the repository). However I made a mistake, I didn't want to commit this new Rails app directly from master, but instead create a new branch from master and push the new Rails app from this new branch.
Therefore, I'd like to:
Delete the commit from master in Github(remote), so master is EMPTY
create a new branch from master and add the previous commit that was in master into this new branch.
push it to Github.
Delete the commit from the master in Github(remote), so master is EMPTY
You can create an orphan branch - orphan branch is branch without any history
# Create "clean" branch
git checkout --orphan <name>
# remove all existing content if you wish
git clean -Xdf && git clean -xdf
create a new branch from master and add the previous commit that was in master into this new branch.
few options:
# Option 1 - Start your branch from the last desired commit
git checkout -b <name> <SHA-1>
# Option 2 - Set your branch to the desired commit
git reset <SHA-1> --hard
# Add the required commit on top of your branch
git cherry-pick <SHA-1>
push it to Github.
# force the update of the new branch
git push <origin> master -f
Please create a new branch from the master with the following command,
git checkout -b branch_name
After that checkout into your new branch and push it to Github.
Now go to the master branch and remove the last commit and push it to Github
You can also try the following steps with your repository:
git checkout master: make sure you are in master.
git checkout -b my-fancy-new-branch: create your new feature branch.
git checkout master: switch back to master
git reset --hard rootcommit: reset master to the state before your own commits.
optional and if you have a remote you pull from: git pull --ff (if this fails because the pull is not fast-forward, you have to reconsider rootcommit. It contains some of your work)
I tried to do this on my test repository, it appears to work.
I have taken a reference from this answer, that can help in finding other approaches too.
I am working with a team on git and my local untracked production branch is missing lines of code from a team member.
My local master branch is tracked on the remote/origin/master and it shows all the code.
The local production branch was checkedout from remote/origin/production with this command
git checkout production
After finishing the development branch I did:
git checkout production
git merge development
I deploy to server and then
git checkout master
git merge development
git merge production
git push origin master
Later I find out that production branch and server are missing some lines of code (while master is ok)
I thought this could be caused by the fact that the remote branch was not tracked with git checkout --track production
Then I found that git diff master..production does not show differences, but analyzing the production branch I can find this commit relative to the merge of the development branch:
git show b17832a
commit b17832ae656f1bd43ebf837934f16b7d1f6efa33
Merge: a9bd850 0873d56
Merge branch 'development'
and here I can find the removed line of code
git diff a9bd850..0873d56 file.rb
diff --git a/file.rb
index e0d1d1b..2343d92 100644
--- a/file.rb
+++ b/file.rb
## -49,12 +49,6 ## angular.module('sp').directive 'spPlayer', [
some text and below I can find
- my missing line of code
- is showing here
how can I fix the production branch and push the change? My commit on master have already been push to the remote.
You mentioned:
Later I find out that production branch and server are missing some lines of code (while master is ok)
Update local production with master then push to remote production (origin/production).
$ git checkout production
$ git merge master
$ git push origin production
Update remote master (origin/master)
$ git checkout master
$ git push origin master
N.B. the issue is solved discussing in OP's comment section actually.
I have two branches in bitbucket and I want to push only some commits (which are approved by me) from one branch to another branch which is a master branch.
Can someone explain to me how I can do it in the bitbucket environment?
Thanks in advance.
you can use git cherry-pick
steps
1. git log
this will list all commits take the commit id which you wanted to move.
2. git cherry-pick <commit-id>
apply this after switching to master branch
3.then push new master to remote
git push <REMOTENAME> <BRANCHNAME>
eg. git push origin master
or
git push <REMOTENAME> <LOCALBRANCHNAME>:<REMOTEBRANCHNAME>
eg:
if my remote name is heroku and i want to push local heroku branch to heroku(remote) master barnch(heroku/master)
git push heroku heroku:maste
links
What does cherry-picking a commit with git mean?
I am new to Git/Heroku/RoR, know basics of these technologies.
I have a git repository repoA which has two branches, master and feature.
I continued working on repoA/feature and upon completion, because the changes were huge so decided to launch a separate app on Heroku to test them first.
So deployed repoA/feature to repoTest/feature on Heroku. Then made some fixes to the feature and finalized the code in repoTest/feature.
Another developer made some commits in repoA/master during this time.
Now I want to make my repoTest/feature LIVE and MERGE it to repoA/master.
Please help me how can I do that ?
NOTE: I have tried doing git rebase master but that did nothing even after a long manual conflict resolve exercise.
As below steps are my normally operations:
1. git checkout repoA/feature
2. git fetch repoTest/feature; git merge repoTest/feature repoA/feature; git stash
3. git checkout repoA/master; git pull origin
4. git checkout repoA/feature; git rebase repoA/master (maybe here you should resolve your conflicts); git stash pop
5. git status; git commit -am ""; git push origin
I'm trying to update the 3-2-stable branch on my fork of the Ruby on Rails project. So after cloning rails, I initially did a git checkout -b my_branch remotes/origin/3-2-stable. Then I made my changes. Then I added my fork as a remote repository with git remote add my_fork git#github.com:myusername/rails.git. Does a git push my_fork my_branch update the 3-2-stable branch only in my_fork? Is there something special I need to do?
Does a git push my_fork my_branch update the 3-2-stable branch only in my_fork?
Yes it will. It won't affect any other repo.
Note that the 3-2-stable on your fork won't be impacted either: a new branch my_branch will be created on your fork to reflect your local branch.
But if you want to push/pull that branch from the repo my_fork, then this would make it easier:
git push -u my_fork my_branch
See "What exactly does the “u” do? “git push -u origin master” vs “git push origin master”" for more on setting the upstream branch of a local branch.