1
1
mirror of https://github.com/namibia/awesome-cheatsheets.git synced 2024-11-24 21:57:38 +00:00

Merge pull request #148 from Charlie-117/master

docs(git): update git.sh
This commit is contained in:
Julien Le Coupanec 2020-11-01 18:24:45 +01:00 committed by GitHub
commit 1f021560e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,7 @@
git init # initiates git in the current directory
git clone <address> # creates a git repo from given address (get the address from your git-server)
git clone <address> -b <branch_name> <path/to/directory> # clones a git repo from the address into the given directory and checkout's the given branch
git clone <address> -b <branch_name> --single-branch # Clones a single branch
git add file.txt # adds(stages) file.txt to the git
git add * # adds(stages) all new modifications, deletions, creations to the git
@ -12,11 +14,16 @@ git status # shows the modifications and stuff that are not staged yet
git branch # shows all the branches (current branch is shown with a star)
git branch my-branch # creates my-branch
git branch -d my-branch # deletes my-branch
git checkout my-bracnch # switches to my-branch
git checkout my-branch # switches to my-branch
git merge my-branch # merges my-branch to current branch
git push origin --delete my-branch # delete remote branch
git branch -m <new-branch-name> # rename the branch
git checkout --orphan <branch_name> # checkout a branch with no commit history
git branch -vv # list all branches and their upstreams, as well as last commit on branch
git branch -a # List all local and remote branches
git cherry-pick <commit_id> # merge the specified commit
git cherry-pick <commit_id_A>^..<commit_id_B> # pick the entire range of commits where A is older than B ( the ^ is for including A as well )
git remote # shows the remotes
git remote -v # shows the remote for pull and push
@ -25,14 +32,24 @@ git remote rm my-remote # Remove a remote
git log # shows the log of commits
git log --oneline # shows the log of commits, each commit in a single line
git log -p <file_name> # change over time for a specific file
git log <Branch1> ^<Branch2> # lists commit(s) in branch1 that are not in branch2
git log -n <x> # lists the last x commits
git log -n <x> --oneline # lists the last x commits, each commit in single line
git grep --heading --line-number '<string/regex>' # Find lines matching the pattern in tracked files
git log --grep='<string/regex>' # Search Commit log
git commit -m "msg" # commit changes with a msg
git commit --amend # combine staged changes with the previous commit, or edit the previous commit message without changing its snapshot
git commit --amend --no-edit # amends a commit without changing its commit message
git commit --amend --author='Author Name <email@address.com>' # Amend the author of a commit
git push my-remote my-branch # pushes the commits to the my-remote in my-branch (does not push the tags)
git revert <commit-id> # Undo a commit by creating a new commit
git show # shows one or more objects (blobs, trees, tags and commits).
git diff # show changes between commits, commit and working tree
git diff --color # show colored diff
git diff --staged # Shows changes staged for commit
git tag # shows all the tags
git tag -a v1.0 -m "msg" # creates an annotated tag
@ -49,7 +66,7 @@ git stash -u # stash everything including new untracked
git stash save "msg" # stash with a msg
git stash list # list all stashes
git stash pop # delete the recent stash and applies it
git stash stach@{2} # delete the {2} stash and applies it
git stash pop stash@{2} # delete the {2} stash and applies it
git stash show # shows the description of stash
git stash apply # keep the stash and applies it to the git
git stash branch my-branch stash@{1} # creates a branch from your stash
@ -65,6 +82,11 @@ git clean -f -d/git clean -fd # To remove directories permanently
git clean -f -X/git clean -fX # To remove ignored files permanently
git clean -f -x/git clean -fx # To remove ignored and non-ignored files permanently
git config --global --list # lists the git configuration for all repos
git config --global --edit # opens an editor to edit the git config file
git config --global alias.<handle> <command> # add git aliases to speed up workflow , eg. if handle is st and command is status then running git st would execute git status
.gitignore
# is a file including names of stuff that you don"t want to be staged or tracked.
# You usually keep your local files like database, media, and etc here.
@ -74,4 +96,3 @@ git clean -f -x/git clean -fx # To remove ignored and non-ignored files perm
# is a hidden directory in repo directory including git files. It is created after "git init".