Git: Check Current Branch & PR/Merge Workflow

Git: Check Current Branch & PR/Merge Workflow

Checking the current branch

See which branch you’re on and status:

git status

Shows “On branch <name>” and whether you’re ahead/behind origin.

List all local branches (current one has *):

git branch

List all branches including remotes:

git branch -a

Show only the current branch name:

git branch --show-current

Switch to an existing local branch

git checkout branch-name
git switch branch-name

Process to create a Pull Request and merge into master (origin)

1. Work on a feature branch (not master):

git checkout -b your-branch-name

Or switch to an existing branch:

git checkout your-branch-name

2. Make changes, then commit on that branch:

git add .
git commit -m "Your commit message"

3. Push the branch to origin:

git push -u origin your-branch-name

(Use -u the first time to set upstream; after that you can use git push.)

4. Create a Pull Request on GitHub:

  • In the browser: Go to your repo on GitHub → “Compare & pull request” (after the push), or Pull requestsNew pull request.
  • Set base branch to master (or origin/master) and compare branch to your-branch-name.
  • Add title/description and create the PR.

5. Merge the PR into master:

  • On GitHub: Open the PR → Merge pull request → confirm (and optionally delete the branch).
  • Or merge locally then push:
    git checkout master
    git pull origin master
    git merge your-branch-name
    git push origin master
    

Useful checks along the way:

git status
git branch -a
git log --oneline -5