Skip to content

Files

Latest commit

 

History

History

git

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

This file is part of eRCaGuy_hello_world: https://github.com/ElectricRCAircraftGuy/eRCaGuy_hello_world

Useful Git References

...including many answers I've written myself:

  1. My answer: Various ways to create a branch in Git from another branch
  2. My answer: All about checking out files or directories in git
  3. My answer: How to cherry-pick a single commit, multiple commits, or a range of commits
  4. Official Git documentation: https://git-scm.com/docs/gitrevisions - mentions git commit 3 dot (...) vs 2 dot range syntax, ^commit ("not" commit), commit^ (the parent of commit), etc.
  5. What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?
  6. My answer: Who is "us" and who is "them" according to Git?
  7. My answer: How to use git diff filters via --diff-filter=
  8. My answer: How to use git lfs as a basic user: What is the difference between git lfs fetch, git lfs fetch --all, and git lfs pull?
  9. My Q&A: How to view a linear git log (exclude feature commits), showing only commits to main or merges to main
  10. My Q&A: In a git merge-style workflow, show only the unique commits someone had in their PR (Pull Request) before merging

    You might think of this as showing only the "right-hand parent" or "right-parent" commits, or as a type of git log --second-parent (which doesn't exist) command.

  11. My answer: How can I push a local Git branch to a remote with a different name easily?
  12. My Q&A: How to change the owner of a PR on GitHub / How to commandeer an open GitHub PR
  13. My A: Adding custom git hooks, such as pre-git status and post-git status

Standard git workflow

git status
git checkout main
git pull
# IMPORTANT: useful branch name format: <your_username>_<issue_number>_<description>
git checkout -b gstaples_AB-999_description_of_my_new_feature
# Set the upstream branch to the same name as the local branch; required the **first push** only
git push -u origin gstaples_AB-999_description_of_my_new_feature
# future pushes are simple; verify that the upstream was set correctly:
git push

# REPEAT THE FOLLOWING STEPS AS MANY TIMES AS NEEDED
# ... do work ...
git status
git add -A  # commit all changes
git add .   # commit all changes in the current directory or lower (not the same thing as above)
git status
git commit
git push
# ... write commit message ...
# ... save and close commit message ...

# When ready for a pull request, open GitHub, BitBucket, Gitlab, etc, and open a pull request
# through the web interface. Then, merge the pull request through the web interface. 

# Then, pull the commit you just merged into main, and clean up your local and remote branches:

git status
git checkout main
git pull
# delete the branch locally now that we are done with it
git branch -d gstaples_AB-999_description_of_my_new_feature
# delete the branch remotely now that we are done with it
git push origin --delete gstaples_AB-999_description_of_my_new_feature

Renaming a local and remote branch

Do not create new branches in the web interface, unless it lets you manually specify the branch name so you can follow the useful <your_username>_<issue_number>_<description> convention above. Putting your username first is especially important to help your colleagues identify who owns each branch.

If you do create a branch in the web interface, you cannot rename it easily. You probably cannot rename it in the web interface at all. Instead, you'll have to rename it locally at the command-line with the correct name, set the new upstream and push it to the remote, and then delete the old branch from the remote server, as follows.

Imagine you mistakenly used the web interface to create a new branch that it named feature/some_description. Here's how to fix it to rename it to gstaples_AB-999_some_description instead, both locally and remotely:

git status
git fetch
git checkout feature/some_description
git pull
git branch -m gstaples_AB-999_some_description       # rename the local branch by 'm'oving it
git push origin -u gstaples_AB-999_some_description  # push it to the new remote branch
git push origin --delete feature/some_description    # delete the old remote branch