Important Flags — These are my personal favorites for keeping everything organized.
git reset HEAD -- - get back to the last known commit and unstage others
git add -u - add only the updated, previously committed files
git log --graph --pretty=oneline --abbrev-commit - for a pretty branch history. Create a shell or git alias for easy access,such as git lg
Working with a Remote Repository — Once you get into the flow, you’ll frequently contribute back to larger projects, and possibly managing forks of forks. Here are some tips for doing so.
git fetch --all - downloads all commits, files, and references to branches on all remote repositories so you can then git checkout or pull what you want to work on.
git pull --rebase <remote> <branch> - Merge all commits since your last common commit from the remote branch without creating a merge commit.
git stash - Use this as needed to save uncommitted changes so you can git stash pop them onto a different branch.
git stash pop - bring it back
git add [-A or . or -- <filename>] - Be intentional about what files you add to your commits, especially if you want to open a request to merge them into an upstream project.
git commit -m "commit message" - Most projects have a format they prefer for commit messages. Look at CONTRIBUTING.md files in the project or review previous commits to get an idea of their format.
git push origin <branch> - Push your current branch to your remote titled “origin” and branch named
git checkout -b <new_branch> - A shortcut for git branch && git checkout branch. It’s great for when you want to experiment with an idea and have a new branch to try it out on that can later be merged or deleted.
git checkout master && git pull --rebase - Great to get to the most recent commit for a project you only infrequently follow.
git reset --hard origin/master - For when you inevitably get lost in all the
git-fu and need to get to a known state.
WARNING: this erases all changes, even
commits, since the last commit pushed to
the remote origin on branch master.
git push origin master - For when you inevitably do something right! Send your changes up to your remote titled origin on branch master.
git <cmd> -h - great for quick review of command flags
git <cmd> --help - to dig into the full man pages of the command