Table of Contents

New Developers Working Group

Useful Git Commands

Rebase

If your patch is behind current main, you'll need to rebase it.

  1. Open the git branch
  2. Type: git rebase origin/main –> rebases the current branch to main (you can do this when you have your branch checked out and changes committed, but have not yet pushed it)
  3. If there are merge conflict errors, type: git status
  4. Open the file with the problem in your preferred text editor (notepad++, vim, nano, etc.)
  5. Look for merge conflict markers in the file (>>>) and correct the problems
  6. Type: git add (problem file name)
  7. Repeat steps 4-6 for each additional problem file
  8. Type: git rebase --continue

You can also use the interactive rebase mode to look at a series of commits:

  1. Open the git branch
  2. Type: git rebase -i origin/main
  3. (Optional but recommended) Save this pick list to a separate file, for recovery later if things go wrong
  4. Choose what to do with each line using the commands listed in the comment block (pick, edit, drop, fixup, squash)
  5. Save and close the "to do" file
  6. Follow the prompts to complete each step you specified

If you need to start over, just rebase again and paste in your original pick list.

Squash Commits

If you have multiple commits in your local branch that you'd like to combine:

  1. Use 'git log' to verify that the commits you want to combine are the most recent
  2. Type git rebase -i HEAD~2 (where 2 is the number of commits you wish to combine)
  3. Your text editor will open and should show both of the commits, for example:
    • pick 014e59c579 LP#1839359 Select element on login not accessible
    • pick 9de92lsi9a LP#1839359 Select element on login not accessible
  4. Change the word "pick" in the second line to either "fixup" or "squash" then save and close the file
    • squash –> merges commits, then allows amendment of commit message
    • fixup –> merges commits like squash does, but discards previous commit message
  5. Use "git commit –amend" if you need to edit the final commit message
  6. Push the changes up to your remote working directory as normal
    • git push working user/jdoe/lp1839359_login_select

If you've already pushed multiple commits up to your remote working git repository, you can still combine them:

  1. Follow the steps above, but when pushing, use "–force"
    • git push --force working user/jdoe/lp1839359_login_select

Aliases

Shortens normal commands so you type less:

$ git config alias.co checkout
$ git config alias.cp cherry-pick
$ git config alias.br branch
$ git config alias.ci commit
$ git config alias.st status