Skip to content

Instantly share code, notes, and snippets.

@rek
Last active August 27, 2019 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rek/f3ac813b498ce7523e6b to your computer and use it in GitHub Desktop.
Save rek/f3ac813b498ce7523e6b to your computer and use it in GitHub Desktop.
GIT CHEATSHEET

==== Ohhh did you FORGETS yeS? ====

save passwords for 10 hours

git config --global credential.helper cache

git config credential.helper 'cache --timeout=36000'

BRANCHES (checkout https://github.com/rek/devconfig too now):

to see what branches exist and which one we are on

git branch -v

or after 2.7 (or change global page config)

git branch -v >> branches
cat branches
rm branches

change to a branch

git checkout branchname

create a branch from the current place

git checkout -b branchname

delete a remote branch NOTE: the ':' means delete, as it is copying from the left of the colons, which is nothing, to the branchname

git push origin :branchname

delete a local branch

git branch -D branchname

TAGS:

add tag

git tag -a v0.1 -m 'init'

list tags

git tag -n

back tag

git tag -a v0.2 -m 'version 1.2' 9fceb02

to push your tags to the remote (origin not required)

git push origin --tags

rename a tag

git tag new old
git tag -d old

to take the remote version in a conflict

git checkout --theirs filename.php

to restore a rm'd file

git checkout HEAD filename.php

revert the last commit

git reset --soft HEAD^

revert an old file

git reset ##number filename

to restore a stash

git checkout stash filename

to add to a remote repo for the first time

git remote add origin https://user@url.org/project.git
git push -u origin --all

to change remote repo

git remote set-url origin https://github.com/user/repo2.git

to view remote

git remote -v

to merge something into the place we are at

git merge dev <- say if we are in master, then this will merge dev into here.

SUBMODULES:

to update:

git submodule update --remote --recursive

?

git push --recurse-submodules=on-demand

to init:

git submodule update --init --remote submodule-path

to create:

git submodule add user@url.com/project.git submodule-path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment