0

For an interview I was asked to refactor an existing project. From the github repository I was given, I was told to: Create a new branch, make updates, commit changes, push to new branch. Then I was told to create a PR with master as the base branch and change the base branch to the forked [company] repository's master branch.

Since I've only worked on my own projects before, I have no idea what to do here. I've been googling and trying to figure it out on my own but can't figure it out.

2
  • 2
    Please check the 2 links guides.github.com git-scm.com/doc Commented Mar 2, 2020 at 16:08
  • 3
    Where exactly is the issue? Have you never used git before? Then you need to read up on some git tutorials. Have you used git but don't know how to interact with Github? Then read their documentation. It's really hard to figure out what exact point you're having problems with. If you can't figure it out then maybe one approach would be to be honest about that and tell your interviewer that you've not worked with git/github before and it's outside your skillset. Commented Mar 2, 2020 at 16:12

2 Answers 2

5

Create a new branch:

Clone/pull the repository and make the new branch:

git pull / git clone [repository] git checkout -b [name_of_new_branch] 

You should get a message saying "Switched to a new branch 'branch name'" NOTE: If you have not been added as a Contributor to the repository, you may need to Fork the project instead.

Pushing the branch to github:

git commit -a -m "commit message" git push origin [name_of_new_branch] 

When you want to commit something in your branch, make sure you're in the branch. Check all branches using:

git branch -a 

There should be an asterisk * next to the branch you're in.

Creating a PR (Pull Request) with the Base Branch (the one you want the changes applied to) as Master:

On the Github Repository page, in the "Branch" menu, choose the branch that contains your commits. Then to the right of the Branch menu, click "New pull request".

Use the "base" branch dropdown menu to select the branch you'd like to merge your changes into. Then use the "compare" branch drop-down menu to choose the branch you made your changes into (the new branch you made).

Give the PR a title and description, and click "Create Pull Request".

Sign up to request clarification or add additional context in comments.

2 Comments

Should we do ` git push --set-upstream origin dev`?
@alper You can, yes. Depending on your needs, you don't need to set an upstream, but doing so will make your life much more convenient when using git commands. For more info on using --set-upstream, check out this answer: link
1
  1. git checkout -b name-of-new-branch
  2. make updates
  3. git commit -am 'updated branch'
  4. git push origin name-of-new-branch
  5. create pull request for name-of-new-branch into master

Why do we do this? Ideally someone should review your pull request and you should not be able to just merge your edits into master before this review. Quality Control

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.