git rev-parse --abbrev-ref HEAD
Show just the current branch in Git
git branch -d feature/#
How can I delete branches in Git?
git push origin --delete feature/#
Can you delete multiple branches in one command with Git?
git checkout -f
CAUTION: commit uncommitted files before executing this command, otherwise you're going to lose them all.
git reset
Undo a git add - remove files staged for a git commit
git reset HEAD~
Create a .gitattributes
file. Then
# Match files that will always have CRLF line endings on checkout
*.bat text eol=crlf
git checkout -- <file>
git reset --hard HEAD^
See Is there any way to undo the effects of “git revert head”?.
For single file:
git rm --cached mylogfile.log
For single directory:
git rm --cached -r mydirectory
git log --oneline --decorate --abbrev-commit -n 20
Show graph.
git log --oneline --decorate --abbrev-commit -n 20 --graph
git checkout -b development
git add .
git commit -m "First commit in the new branch"
Move existing, uncommitted work to a new branch in Git
git push -u origin feature_branch_name
-u
is short for --set-upstream
How do I push a new local branch to a remote Git repository and track it too?
git-push - Update remote refs along with associated objects
git clone <url> --single-branch
# Longer form
git clone <url> --branch <branch> --single-branch [<folder>]
How do I clone a single branch in Git?
git log master..
git log master..<branchname>
How do I run git log to see changes only for a specific branch?
git - changes to branch since created?
git fetch --prune
Also removes completed branch. Sync local repo with remote one
git fetch upstream
git checkout master
git merge upstream/master
Working with forks / Syncing a fork
Sync your Git Fork to the Original Repo
How do I update a GitHub forked repository?
Or
git pull upstream develop
git pull origin other-branch
Which is equivalent to
git fetch origin other-branch && git merge other-branch
See Git pull a certain branch from GitHub.
If the branch exists on origin but not yet locally, do the following.
git fetch
git checkout test
git checkout --track origin/daves_branch
You cannot commit a completely empty directory in Git. The convention is to add a placeholder file named .gitkeep
to the target directory.
- How can I add an empty directory to a Git repository?
- What are the differences between .gitignore and .gitkeep?
git rebase -i origin/master
Typically, you would use git reset --hard origin/master
but in this case I wanted to see how the local master differed from the remote one. See Your branch is ahead of 'origin/master' by 3 commits.
git checkout <old_name>
git branch -m <new_name>
git push origin -u <new_name>
push origin --delete <old_name>
Or
git branch -m new-name
git push origin :old-name new-name
git push origin -u new-name
See Rename a local and remote branch in git
How To Rename a Local and Remote Git Branch
git rm --cached .project
git rm --cached .classpath
git rm --cached -r .settings
Then add to .gitignore
.project
.classpath
.settings/
Example .gitignore
# Eclipse
.classpath
.project
.settings/
# Maven
log/
target/
How to ignore IDE settings on Git?
A .gitignore file for Intellij and Eclipse with Maven
git remote show origin
Or if referential integrity has been broken:
git config --get remote.origin.url
Or simply
git remote -v
How can I determine the URL that a local Git repository was originally cloned from?
Origin
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
Upstream
git remote set-url upstream https://github.com/[Original Owner Username]/[Original Repository].git
git remote set-url upstream git@github.com:[Original Owner Username]/[Original Repository].git
git@github.com:<repo>/<project>.git
git remote add origin https://github.com/gkhays/orientdb-testdrive.git
git push -u origin master
git push --set-upstream origin developer
Create a new repo in bitbucket.
git clone <gitlabRepoUrl>
cd <repoName>
git remote add bitbucket <bitbucketRepoUrl>
git push bitbucket master
How to import gitlab repository to bitbucket Repository
git config --list
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/gkhays/orientdb-testdrive.git
git push -u origin master
git fetch --prune
-p, --prune
After fetching, remove any remote-tracking branches which no longer exist on the remote -- http://stackoverflow.com/a/15124916/6146580
$ git describe --tags
v1.0.1-2-g39918b9
$ git rev-parse --short HEAD
39918b9
Get the short Git version hash
git-rev-parse - Pick out and massage parameters
gti diff patch/feat36..develop
git log patch/feat36..develop
git log --oneline --graph --decorate --abbrev-commit patch/ig36..develop
git diff patch/feat35...patch/feat36 Jenkinsfile
Or
git diff mybranch..master -- myfile.cs
How To Compare Two Git Branches
Comparing two branches in Git?
Showing which files have changed between two revisions
git-diff - Show changes between commits, commit and working tree, etc
How can I see a “three way diff” for a Git merge conflict?
git-merge(1) Manual Page
How to compare files from two different branches
Add the following to ~/.gitconfig
.
[merge]
tool = bc3
[diff]
tool = bc3
[difftool "bc3"]
cmd = "\"C:/Program Files (x86)/Beyond Compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\""
[mergetool "bc3"]
cmd = "\"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\""
Invoke the diff tool.
D:\src\test-remote (master -> origin)
λ git difftool -t bc3 src/main/org/gkh/test/remote/JarCommand.java
Viewing (1/1): 'src/main/java/org/gkh/test/remote/JarCommand.java'
Launch 'bc3' [Y/n]? y
git config --global --unset user.password
Caching your Git Password On Windows
$ git config --global credential.helper wincred
Cachiang your Git Password on Linux
git config --global credential.helper cache
Add optional timeout
git config --global credential.helper cache -timeout=3600
- How do I update the password for Git?
- https://git-scm.com/book/gr/v2/Git-Tools-Credential-Storage
- git credential helper - update password
- Caching Your Password
alias ga='git add'
alias gaa='git add .'
alias gaaa='git add --all'
alias gau='git add --update'
alias gb='git branch'
alias gbd='git branch --delete '
alias gc='git commit'
alias gcm='git commit --message'
alias gcf='git commit --fixup'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcom='git checkout master'
alias gcos='git checkout staging'
alias gcod='git checkout develop'
alias gd='git diff'
alias gda='git diff HEAD'
alias gi='git init'
alias glg='git log --graph --oneline --decorate --all'
alias gld='git log --pretty=format:"%h %ad %s" --date=short --all'
alias gm='git merge --no-ff'
alias gma='git merge --abort'
alias gmc='git merge --continue'
alias gp='git pull'
alias gpr='git pull --rebase'
alias gr='git rebase'
alias gs='git status'
alias gss='git status --short'
alias gst='git stash'
alias gsta='git stash apply'
alias gstd='git stash drop'
alias gstl='git stash list'
alias gstp='git stash pop'
alias gsts='git stash save'
From Git Command-Line Shortcuts.
To initially clone the repository, set an environment variable.
$ export GIT_SSL_NO_VERIFY=1
Then clone:
$ git clone https://<repo>.git
Alternatively, using the -c
switch
$ git -c http.sslVerify=false clone https://github.com/gkhays/cheatsheets.git
It is possible to globally disable certificate verification, --global
, but the best practice is to only do it on repos you trust.
$ git config http.sslVerify false
or
$ git -c http.sslVerify=false
It would be insecure to disable certificate validation on a global basis, so as a rule don't do it, e.g. avoid $ git config --global http.sslVerify false
.
$ git config --system http.sslCAPath /path/to/cacerts
git commit --amend --allow-empty --author="FirstName LastName <name@email.com>"
git commit --amend --reset-author
From WikiLeaks Vault 7
# Issue: When attempting to clone (or any other command that interacts with the
# remote server) git by default validates the presented SSL certificate by the
# server. Our server's certificate is not valid and therefore git exits out with
# an error. Resolution(Linux): For a one time fix, you can use the env command
# to create an environment variable of GIT_SSL_NO_VERIFY=TRUE.
$ env GIT_SSL_NO_VERIFY=TRUE git <command> <arguments>
# If you don't want to do this all the time, you can change your git configuration:
$ git config --global http.sslVerify false
Git vs SVN commands
How can I make git accept a self signed certificate?
How do I set GIT_SSL_NO_VERIFY for specific repos only?
server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
configure Git to accept a particular self-signed server certificate for a particular https remote
Https certificate errors for GitHub using git on Windows 7
Unable to clone Git repository due to self signed certificate
https://github.com/iwonbigbro/tools/blob/master/bin/git-remote-install-cert.sh
Setting up a repository