Git
Git is a widely-used, open-source tool for managing versions of a project.
Configuration
Shell Aliases
Add these aliases to your .bashrc
or .zshrc
to make life easier:
# Git
alias clone="git clone"
alias checkout="git checkout"
alias update="git fetch && git pull"
alias push="git push"
alias commit="git commit -a"
alias add="git add"
alias pull="git pull"
alias status="git status"
alias log="git log --all --decorate --oneline --graph"
alias cherry-pick="git cherry-pick"
export GITHUB_TOKEN="<YOUR_GITHUB_ACCESS_TOKEN>"
export PAT=$GITHUB_TOKEN
Set Global Git User Name/Email
git config --global user.name "FIRST_NAME LAST_NAME"
git config --global user.email "MY_NAME@example.com"
Commands
Useful git
commands for managing a repository.
Sign-off on a Commit
This is different from signing a commit. |
Commit messages should be formatted with the first name, last name, and email address authorized with GitHub for that repository.
Commit message.
first_name last_name <email_address>
For example,
Generate vendor dependencies at build-time
* Remove vendor/ directory
* Generate vendor/ during build
* Gitignore vendor/ dir
* Add go mod vendor to make build
* Add go mod vendor to docker build
* Use go mod download instead of vendor
Signed-off-by: Caleb Carlson <ccarlson355@gmail.com>
Delete a Branch
Delete a local branch:
git branch --delete <branchname>
Make sure you switch to another branch before doing this so you’re not stranded on a deleted branch. |
Example:
➜ hpc-sp-kjplat-img git:(bugfix/SSM-4489) ✗ checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
➜ hpc-sp-kjplat-img git:(master) ✗ git branch --delete bugfix/SSM-4489
warning: deleting branch 'bugfix/SSM-4489' that has been merged to
'refs/remotes/origin/bugfix/SSM-4489', but not yet merged to HEAD.
Deleted branch bugfix/SSM-4489 (was 8d7abea).
Delete the remote branch:
git push origin --delete <branchname>
Example:
➜ hpc-sp-kjplat-img git:(master) ✗ git push origin --delete kjplat-634
To github.hpe.com:hpe/hpc-sp-kjplat-img.git
- [deleted] kjplat-634
You can also use the GitHub repository web UI to delete the remote branch.
Push Repo to New Upstream
If you’ve cloned out a repo from one source, like GitLab, and would like to push it to a blank GitHub repo,
you can do so easily by adding an upstream
remote to your Git workflow.
-
Add an upstream
git remote add upstream git@github.com:inf0rmatiker/antora-site-ui.git
-
Push your master or main branch to your new upstream
git push upstream master