git
git is a source code versioning tool.
Setting up
-- setup aliases
$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status
$ git config --global alias.sha "rev-parse --short HEAD"
-- setup config
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
Most recent commit hash - to use for build versioning
$ git reverse-parse HEAD
3d548f8ba82715fc4b1bf43b788b08364f8a8cc9
$ git rev-parse --short HEAD
3d548f8
$ git log -1 --format="%h"
3d548f8
Get a list of remotes
-- remote repositories
$ git remote -v
-- remote branches
$ git branch -r
Submodules
Add a submodule
-- add a submodule
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
Update a submodule
-- update the submodule
git submodule update --remote
Populating a submodule on checked out repo
There are two ways to do this. The automatic way, you add options to your git clone command to pull in submodules. In the manual way, you run extra commands to pull the submodule.
-- Automatically pull submodules on git clone
git clone --recurse-submodules https://github.com/me/myproject
-- Manual way, run these after you've cloned the repo to populate the submodule
git submodule init
git submodule update
Troubleshooting
git push fails because of remote changes not merged
If you try to git push
and receive an error because the remote has changes. You can do a git pull with rebase and then push.
$ git push
error: failed to push some refs to 'git@github.com:me/my-repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git pull --rebase
$ git push