git status
lets you know which branch your on, whether the working tree is modified
does not let you know whether there are upstream changes
git fetch
recursively pulls down all commits in all branches and submodules
does not modify your working tree
tig --all
list all commits and all branches, highlights your current checked out commit in cyan
git pull
fetches the current repo (non recursive) and merges origin/ into your current branch
will fail if you have modifications in any of the changed files
git merge [origin/]<branchname>
merges the branchname into your current commit.
git checkout [origin/]<branchname>
can only be done if your working tree is clean, checks out the latest commit in that branch.
you can also use git checkout <commit hash>
to checkout a particular commit.
if you checkout origin/ or then you are no longer on a branch.
git commit -a -m "<message name>"
add all modified files to the working tree, and commit them with the given message
git submodule update --init --recursive
initialises any new submodules, updates all submodules to point to the commit which is pointed to, and does so recursively into all submodules' submodules.
you cannot perform a 'submodule update' if there are changes in a submodule.
updating the reference to a submodule
if you go into a submodule and make changes, you must commit and push it before going back to the previous folder.
in the previous folder you should see 'new commits', so just git add <submodule name>
and commit it, usually with a message like 'updated ref'.
if you forget to push the submodule before updating the ref and pushing the ref change, people who try to checkout your commit will have a bad time.
git push
pushes local new commits. fails if the remote branch has newer commits than you. try a 'pull' first
pushes all branches, so you might want to delete obsolete local branches which have fallen behind and you're not using for now
git checkout -b <branchname>
creates a new branch from the commit you're on now. make sure to push it using the below command!
git push -u origin <branchname>
pushes the new branch you created to origin
git branch -d <branchname>
deletes a local branch. good for cleanup otherwise git push
will start whinging about local branches being behind
git reset --hard
resets the working tree to the state in the commit
note that this deletes any changes you've made
also note that it does not remove any new files that are there
Not being on a branch
if you type git status
and it says no branch, then you are not on a branch.
you can still make changes and commits, however the commits will be difficult to find once you do checkout a branch.
When you checkout a branch, it will warn you, and give you the hash of the latest commit. you should then git merge <commit hash>
to get those changes back into your branch.
You can bet into a 'not on a branch' state by either checking out a particular commit, checking out origin/, or being in a submodule who was pointing to a particular commit.
git fsck --lost-found
lists commits which were made not on a branch.
git branch -a --no-merged
lists branches which are not merged into your current branch
git rev-parse HEAD
display hash of current commit
git tag
list all tags
git tag <tagname>
make a new tag
git push --tags
push the new tags up
git push --delete origin <tagname>
delete remote tags
git fetch --prune --tags
prunes local tags
git revert <commit>
undo the changes introduced in a particular commit
git push origin --delete
git remote prune origin
git diff ...<other branch>
See which changes would be introduced if you were to merge that branch in
git describe --long --tags --match
it's a secret to everybody
Patching: https://gist.github.com/deanrather/44bf0d4988730ecf1e7d