Created Sun Jun, 09 2019 at 11:23AM
bugfix/branch-foo
again:git push origin :bugfix/branch-baz (note the colon)
git reset --hard ABCDE
git push origin bugfix/branch-baz
git config --global user.name "Jaime Carranza"
git config --global user.email "Jaime@Carranza.co"
git config --global color.ui true
git config --global core.editor "vim"
git config --get remote.origin.url
git push origin --delete the_remote_branch
# will hide it globally.
git config --global oh-my-zsh.hide-status 1
# hide per repo
git config oh-my-zsh.hide-status 1
git init
# initializes a git project
git add .
git add /path/foo.bar
git commit -am "this is a commit message"
echo "logs\n*.log\ntmp" > .gitignore git add .gitignore git commit .gitignore -m "adding git ignore"
f you haven't yet commited the changes, then:
git diff > mypatch.patch
But sometimes it happens that part of the stuff you're doing are new files that are untracked and won't be in your git diff output. So, one way to do a patch is to stage everything for a new commit (but don't do the commit), and then:
git diff --cached > mypatch.patch
Add the 'binary' option if you want to add binary files to the patch (e.g. mp3 files):
git diff --cached --binary > mypatch.patch
You can later apply the patch:
git apply mypatch.patch
git log --oneline
git log --oneline --graph
git log --pretty="%h, %cn, %cr" # * list provided in tail of file
gitk (tk gui)
git has it's own way of creating aliases to internal methods example: we want to make shortcut "s" map to command status
git config --global alias.s status git config --global alias.co checkout git config --global alias.cm commit
alias gs="git status"
alias gc="git commit"
alias gi="git add -i" # interactive add
alias gl="git log --oneline --graph --all --decorate"
git stash
takes the dirty state of your working directory
git stash list
stash@{0}: WIP on feature/GS-1761-a....
stash@{1}: WIP on GS-1660-tsc....
git stash apply stash@{1}
git stash show -p stash@{0}
git stash drop stash@{1}
Assuming you did not commit the file, or add it to the index, then:
git checkout -- filename
Assuming you added it to the index, but did not commit it, then:
git reset HEAD filename
git checkout -- filename
Assuming you did commit it, then:
git checkout origin/master filename
Assuming you want to blow away all commits from your branch (VERY DESTRUCTIVE):
git reset --hard origin/master
git add -p goes hunk by hunk in a file. (s - split hunk)
git remote add
pushing changes from our local git copy to a remote
git push origin master
git pull
down changes from remote to local git
git fetch
to pull down changes but allow us to merge them in ourselves
git merge origin/master master
to go ahead and merge all the changes from the remote and our local master
git clone git://someurl
'%H': commit hash
'%h': abbreviated commit hash
'%T': tree hash
'%t': abbreviated tree hash
'%P': parent hashes
'%p': abbreviated parent hashes
'%an': author name
'%aN': author name (respecting .mailmap, see git-shortlog[1] or git-blame[1])
'%ae': author email
'%aE': author email (respecting .mailmap, see git-shortlog[1] or git-blame[1])
'%ad': author date (format respects --date= option)
'%aD': author date, RFC2822 style
'%ar': author date, relative
'%at': author date, UNIX timestamp
'%ai': author date, ISO 8601-like format
'%aI': author date, strict ISO 8601 format
'%cn': committer name
'%cN': committer name (respecting .mailmap, see git-shortlog[1] or git-blame[1])
'%ce': committer email
'%cE': committer email (respecting .mailmap, see git-shortlog[1] or git-blame[1])
'%cd': committer date (format respects --date= option)
'%cD': committer date, RFC2822 style
'%cr': committer date, relative
'%ct': committer date, UNIX timestamp
'%ci': committer date, ISO 8601-like format
'%cI': committer date, strict ISO 8601 format
'%d': ref names, like the --decorate option of git-log[1]
'%D': ref names without the " (", ")" wrapping.
'%e': encoding
'%s': subject
'%f': sanitized subject line, suitable for a filename
'%b': body
'%B': raw body (unwrapped subject and body)
'%N': commit notes
'%GG': raw verification message from GPG for a signed commit
'%G?': show "G" for a good (valid) signature, "B" for a bad signature, "U" for a good signature with unknown validity, "X" for a good signature that has expired, "Y" for a good signature made by an expired key, "R" for a good signature made by a revoked key, "E" if the signature cannot be checked (e.g. missing key) and "N" for no signature
'%GS': show the name of the signer for a signed commit
'%GK': show the key used to sign a signed commit
'%gD': reflog selector, e.g., refs/stash@{1} or refs/stash@{2 minutes ago}; the format follows the rules described for the -g option. The portion before the @ is the refname as given on the command line (so git log -g refs/heads/master would yield refs/heads/master@{0}).
'%gd': shortened reflog selector; same as %gD, but the refname portion is shortened for human readability (so refs/heads/master becomes just master).
'%gn': reflog identity name
'%gN': reflog identity name (respecting .mailmap, see git-shortlog[1] or git-blame[1])
'%ge': reflog identity email
'%gE': reflog identity email (respecting .mailmap, see git-shortlog[1] or git-blame[1])
'%gs': reflog subject
'%Cred': switch color to red
'%Cgreen': switch color to green
'%Cblue': switch color to blue
'%Creset': reset color
If you are on the branch you want to rename:
git branch -m new-name
If you are on a different branch:
git branch -m old-name new-name
git push origin :old-name new-name
Switch to the branch and then:
git push origin -u new-name
or
Follow the steps below to rename a Local and Remote Git Branch:
git checkout <old_name>
git branch -m <new_name>
At this point, you have renamed the local branch.
If you’ve already pushed the <old_name>
branch to the remote repository , perform the next steps to rename the remote branch.
<new_name>
local branch and reset the upstream branch:git push origin -u <new_name>
<old_name>
remote branch:git push origin --delete <old_name>
That’s it. You have successfully renamed the local and remote Git branch.
# oops you committed a tag but ended up pushing some extra files and now need to move the tag forward.
# remove from remote
git push --delete origin tagname
# remove from local
git tag --delete tagname
# now add tag like normal.
# list tags
git -l
# list with filter
git -l 'multi*'
Found this excellent article explaining out to get out of a corner I painted myself into. It was brilliantly simple worked like a charm.
The gist being, simple switch into the branch you want to merge files into, then git checkout the files from the other branch.
git checkout my-target-branch
git checkout source_branch file2 path/to/file2 etc..
First, checkout to your BranchFoo:
git checkout BranchFoo
Then merge the BranchBar:
git merge BranchBar