Hi, I am a real beginner on GIT and this is basic concept question with basic how to question.
My understanding is
1. Create main/master repository on cloud and clone/copy the repository as a branch(let's say A branch)
2. A branch has same files as Master branch
3. Using "git clone" and bring all files to local repo.
In this step, I only can clone master branch. Can I clone A branch?
4. Edit/create files in local.
5. Using "git add, git commit" and put changes to my local repo
6. Using "git push" and put it on A branch in cloud
In this step, my changes go to master branch.
Isn't this go to A branch and I follow PR, approve and merge steps?
My questions are
How can I push my local changes to A branch, not master.
How can I set master branch to deny direct push from local.
Hi, @Young Joe - welcome to the Community!
You use clone only once, generally - to get an existing remote repo onto your local machine. Once you've done that, all future work on that repo would be done using checkout.
To check out a new branch from a remote branch other than master (in this example, it's develop; change that to whatever your remote branch is):
git checkout -b <new branch name> origin/develop
To push a local commit to a specific remote branch:
git push origin <remote branch name>
However, if the end goal is to get your changes into master, usually you'd just do git push, which would result in the remote repo having a copy of your local branch. When you create a pull request, the origin is the copy of your branch; the destination is master.
Here's an example - I have a repo called atlassianScripts. I don't have a develop branch, only master, but you can pretend I'm doing a pull from another branch if it helps :)
You can see from the first line of my bash window that the local branch I was previously working on was called estrom/jira-1551. It had already been committed and pushed, so it was safe to just do a new pull from the server (git fetch origin).
I then checked out a new branch from origin/master called estrom/jira-1800 (this is where you'd choose another branch to pull from if you have a develop branch, or a release branch you need to work from.)
After making changes to my files, I do a git commit - in this case, since I didn't add any new files, there was no need for git add; I'm just committing changes to existing files. I include the jira ticket number as the first part of the commit message so the commit (and subsequent pull request) is linked to the Jira ticket in bitbucket and jira.)
I then just do a git push, no branch specified.
Now, I go into Bitbucket (or github if that's what you're using) and create a pull request.
You can see that the branch I had created locally and pushed is now the origin of the pull request (the one on the left) and master is the branch the code will be merged to once the pull request is approved.
Hope that helps! Atlassian has a really great series of git tutorials that would be a great starting point.
Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events