Which is "clones" counted in the Clone Graph, master or origin? - git-clone

When I did "git clone", the Clone Graph shows "unique cloner=1 and clones=2".
Tell me why pls.

your question is like this
it's duplicated.
There are actually three things here: origin master is two separate things, and origin/master is one thing. Three things total.
Two branches:
master is a local branch
origin/master is a remote branch (which is a local copy of the branch named "master" on the remote named "origin")
One remote:
origin is a remote
Example: pull in two steps
Since origin/master is a branch, you can merge it. Here's a pull in two steps:
Step one, fetch master from the remote origin. The master branch on origin will be fetched and the local copy will be named origin/master.
git fetch origin master
Then you merge origin/master into master.
git merge origin/master
Then you can push your new changes in master back to origin:
git push origin master
More examples
You can fetch multiple branches by name...
git fetch origin master stable oldstable
You can merge multiple branches...
git merge origin/master hotfix-2275 hotfix-2276 hotfix-2290

Related

Reset master to an empty state

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.

Restore merged branch in bitbucket

Long back I have created a pull request to merge my branch into master and it was done. I think the merged branches will not be available on Bitbucket for longer time? (Anyway, my branch is not available).
But, is there a way to recover that branch in Bitbucket?
I know how to recover it on git/sourcetree, but I want in Bitbucket to create another branch from this.
I have used this command to recover my branch to sourcetree,
git checkout -b <branch> <sha>
Created a tag from last commit of my branch and created branch from that tag.

Using git pull properly

I am new to git so please bear with me. I have a rails application on my local machine that I am experimenting with and pushing to the master branch periodically. It works at the moment, but I have fallen behind, and now I am many commits behind the master.
$ git branch
* master
$ git status
On branch master
Your branch is behind 'origin/master' by 27 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working tree clean
However, when I use git pull and then start rails, my application breaks with a precompiler error. So I am forced to use git --reset to go back to the local commit before I used git pull.
What is the right way to get around this issue and merge with the latest changes on the master branch? Would one use git --rebase in this case?
Try
git stash
git pull origin master
And once it updates, git stash apply to reapply your local changes
Since nobody has stated this clearly yet: You ask
What is the right way to get around this issue and merge with the latest changes on the master branch?
When you do git pull that does merge the remote changes into your current branch. Whether you would choose to do a rebase instead of a merge (per your other question) is a separate issue, but the default behavior is to combine the two sets of changes (local and remote).
More precisely, by default git pull does a fetch followed by a merge. The exact merge operation depends on configuration and on command-line options, but in a typical configuration where origin/master is upstream of master, saying
git pull
will merge origin/master into master.
So why the errors?
One possibility is that there were merge conflicts. If that happens, git will tell you. If you say git status in this condition, it will tell you that there's a merge in progress and it will indicate which paths (files) need conflict resolution.
Another possibility is that the changes don't conflict (in that they don't affect the same region of the same file) but still don't work properly together. That you would simply have to debug.

How push approved commits from one branch to another branch in bitbucket

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?

How to clone the code from master branch in Bitbucket?

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.

Resources