Skip to content

GitΒΆ

Git ConfigurationΒΆ

git configΒΆ

Exclude files permission from all local changes

git config --global core.fileMode false
git config --local core.fileMode false

Update git config

git config --unset core.bare

Change git default editor

git config --global core.editor "vim"

Skip SSL C.AΒΆ

Skip unable to access https://your.host/your-git/your-repor.git/ SSL certificate problem: self signed certificate

git config --global http.sslVerify false

Specified KeysΒΆ

Add github to your hosts ~/.ssh/config

Host github
  HostName github.com
  IdentityFile ~/.ssh/id_rsa_home

store username passΒΆ

git config --global credential.helper store

Git CommandsΒΆ

Git 3 level conceptΒΆ

git three level concept

pic1 pic2 pic3

git fetchΒΆ

git fetch/pull

git-pull-fetch

git addΒΆ

Add file to stage except one

git add --all -- :!main/dont_check_main.txt
git add -- . :!main/dont_check_main.txt

Add a new line at EOF

git add --renormalize <file-name>

git cloneΒΆ

Clone and checkout simultaneously

git clone -b <branch name> address

Clone repo

git clone --mirror git@github.com/fernandoaleman/app.git app/.git

git logΒΆ

Git log arguments

git log --pretty=oneline
git log --pretty=format:"%h - %an, %ar : %s"
git log --max-count 3
git log --oneline --max-count 5
git log --since="3 days ago"; (--since, --after, --until, --before)
git log --graph --oneline --decorate --all

git checkoutΒΆ

Checkout master branch

git checkout master

Create new branch and switch to it

git checkout -b <New_Branch>

Checkout via origin branch

git branch -a
git checkout -b <branch-name> origin/<branch-name>

Checkout over tag number

git checkout tags/4.3.87

Check it up

git branch

Go to last 3 commit

git checkout HEAD~3

git remoteΒΆ

Add new remote repository

git remote add origin https://github.com/username/git-project-repo.git
git remote add origin git@github.com:username/git-project-repo.git

Rename an existing repo

git remote rename <old-name> <new-name>

Get the list of the remote repository

git remote -v

git branchΒΆ

Create new branch

git branch <new-branch>

Rename a branch

git branch -m <old> <new>

Delete a branch

git branch -d <branch_name>

git switchΒΆ

Switch branch

git switch <existing-branch>

Point head to last commit

git switch -

git reset - git revertΒΆ

Git resetΒΆ

git reset --soft <commit-id>
git reset --mixed <commit-id>
git reset --hard <commit-id>
All git reset options

git_reset_options

Git revertΒΆ

git revert <commit-id>
git revert

git-revert

git tagΒΆ

git tag -a v1.0 8489c03c1 -m "version 1.0 is released"

git rebaseΒΆ

Reapply commits on top of another base tip

git rebase master topic
Assume the following history exists and the current branch is "topic":
              A---B---C topic
            /
        D---E---F---G master

From this point, the result of either of the following commands:

    git rebase master
    git rebase master topic

would be:

                      A'--B'--C' topic
                    /
        D---E---F---G master
Get more view of 'git rebase'

pic1

Delete an old commit

git rebase --interactive <commit-hash-before-target-commit>

Then use keyword drop inside the target commit hash and save the file

git push -f origin branch-name

Note: the -f is a required parameter for this step

Rebase & Merge Conflict, step by step guidΒΆ

git merge vs git rebaseΒΆ

git merge / git rebase

git-merge-rebase-1 git-merge-rebase-2

Checkout to main branch

git checkout master

Give it the last changes from main branch of remote repository

git pull origin master

Check the branches and go to target branch

git branch -a
git checkout target-branch

Give the last changes from main branch of local repository

git rebase master

NOTE: Git makes new temp branch and apply all changes to it until `git rebase --continue Apply changes and get status then add

git status
git add .

Put temp branch changes to target-branch

git rebase --continue

Push to remove target-branch

git push -f origin target-branch

NOTE: You should solve the merge conflict manually by your TE or IDE if you have

Some Important GIT CommandsΒΆ