💡
Knowledge
  • Home
  • Technology
    • Browser
      • Chrome / Brave
        • Known Issues
    • Messaging
      • Discord
        • Known Issues
      • Microsoft Teams
      • Telegram
    • Office Production
      • Sheets
    • Music Production
    • Operational systems
      • Docker + OSX
      • Raspberry Pi OS
      • Linux
        • Terminal
        • Known Issues
        • Desktop Environment
          • Gnome
            • How to
            • Known Issues
            • Theming
          • Kde Plasma
        • How to
          • Audio
          • Proxy
          • SSH
          • ZSH
      • Windows
    • Programming
      • Code Quality
        • Stress Tests
      • Cascading Style Sheets(CSS)
      • Database
        • Postgres
        • SQLServer
      • Design Patterns
      • DevOps
        • Cloud Platforms
        • Continuous Integration
        • Docker
          • How to
          • IPSEC VPN Server
          • Docker Compose
          • Known issues
          • Proxy
        • Swarm
      • Git
        • How to
        • Known Issues
        • Github
        • Gitlab
          • GitlabCI
          • Gitlab Runner
      • IDE / Text Editor
        • Vim
          • Commands
        • PHPStorm
        • VSCode
      • Programming Languages
        • Typescript
        • Java
          • How to
          • Spring Boot
        • Javascript
          • Known issues
          • Backend
            • NestJS
            • NodeJS
          • Frontend
            • JQuery
            • React
            • Vue
          • How to
          • Package Manager
            • Yarn
          • Packages
          • Vanilla
        • PHP
          • About
          • Cache
          • Composer
          • Docker
          • How to
          • Known Issues
          • Laravel
            • Jet Stream
            • Know Issues
            • Sanctum
            • Sail
            • Valet
          • Tools
            • PHPUnit
          • Wordpress
            • Docker
            • WP CLI
            • Known Issues
            • WooComerce
        • Python
        • Shell Script
      • Server
        • Apache2
          • Known Issues
        • Nginx
          • How To
          • Known issues
      • Tools
        • Visual Studio Code
    • Stream
      • Game
      • Twitch
      • Tests
        • Unit Tests
    • Sites
    • Specs
    • Tools
  • Pessoal
    • About me
Powered by GitBook
On this page
  • Push
  • Push to a remote specific branch
  • Push ignoring verify or hooks
  • Ignore all files in this folder
  • Get current branch
  • Cache
  • Clear Entire Git Cache
  • Cache user and password
  • Stash
  • Stash including untracked files
  • Stash only file or folder
  • Revert
  • Revert files from a specific hash commit
  • Revert to a specific commit
  • Reset
  • Reset Permissions
  • Use globally
  • Reset by time
  • Undo the last commit
  • Rename
  • Rename your branch
  • Logs
  • Find versioned files
  • View git logs of just one author commits
  • View git logs of many authors commit
  • Exclude git commits log from one or more author
  • Proxy bypass to specific host
  • Fixing wrong commit messages
  • Deleting remote branches
  • Keeping a fork up to date
  • Clone your fork:
  • Add remote from the original repository in your forked repository:
  • Updating your fork from the original repo to keep up with their changes:
  • How to use prune to Clean Up remote branches
  • Using "prune" on a Remote Repository
  • Tags
  • Create and tag with a message

Was this helpful?

  1. Technology
  2. Programming
  3. Git

How to

Push

Push to a remote specific branch

Assuming as an example that the remote upstream has been added and you need to send code from the local branch develop to the remote branch dev-master, to be able to execute this operation just execute the command below:

git push upstream develop:dev-master

Push ignoring verify or hooks

git push github develop:master --no-verify

Ignore all files in this folder

When you want to ignore files but want to keep a directory you can add a .gitignore file within the desired directory with the following content

*
!.gitignore

Get current branch

git branch --show-current

Cache

Clear Entire Git Cache

To clear your entire Git cache, use the “git rm” command with the “-r” option for recursive

 git rm -r --cached .

When all files are removed from the index, you can add the regular files back (the one you did not want to ignore)

git add .
$ git commit -am 'Removed files from the index (now ignored)'

Cache user and password

git config credential.helper store
git config --global credential.helper 'cache --timeout 7200'

Stash

Stash including untracked files

git stash --include-untracked

Stash only file or folder

git stash push path/to/file

Revert

Revert files from a specific hash commit

git checkout 3df73866bef5d560ef2e5s59b6deaa18001 -- wp-content/uploads/2011 wp-content/uploads/2012 

Revert to a specific commit

git revert --no-commit 0766c053..HEAD

Reset

Reset Permissions

When you accidentally modify the permissions of versioned files, it is possible to return to the initial permission state using the command below

git diff -p -R --no-ext-diff --no-color \
    | grep -E "^(diff|(old|new) mode)" --color=never  \
    | git apply

Use globally

If you want to use globally, you can do it that way:

git config --global --add alias.permission-reset '!git diff -p -R --no-ext-diff --no-color | grep -E "^(diff|(old|new) mode)" --color=never | git apply'
git permission-reset

Reset by time

git reset --hard master@{"300 minutes ago"}

Undo the last commit

 git reset --soft HEAD~1

Rename

Rename your branch

git branch -m new-name

If you are on a different branch:

git branch -m old-name new-name
  • Delete the old-name remote branch and push the new-name local branch.

git push origin :old-name new-name

  • Reset the upstream branch for the new-name local branch.

Switch to the branch and then:

git push origin -u new-name

Logs

Find versioned files

To find files that have been versioned, regardless of whether they were removed from versioning or not.

git log --all --full-history -- "**/thefile.*"

View git logs of just one author commits

# Only commits by Vinicius
git log --author="Vinicius"

# Use "--all" to search all branches
git log --author="Vinicius" --all

View git logs of many authors commit

# Many Authors
git log --author="\(Vinicius\)\|\(Jose\)"

Exclude git commits log from one or more author

git log --author='^(?!Vinicius|Jose).*$' --perl-regexp

Proxy bypass to specific host

# Globally
git config --global add remote.{remote_name} proxy 

# Locally
git config --local --add remote.{remote_name}.proxy ""

Fixing wrong commit messages

git rebase -i HEAD~4

Deleting remote branches

git push origin --delete branchName

Keeping a fork up to date

Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

Add remote from the original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream

Updating your fork from the original repo to keep up with their changes:

git pull upstream master

How to use prune to Clean Up remote branches

Using "prune" on a Remote Repository

The easiest way to use prune is to provide it as an option when fetching:

$ git fetch --prune origin

In cases where you'd like to only perform a prune and not fetch remote data, you can use it with the git remote command:

$ git remote prune origin

If you want to have prune executed with every fetch operation, you can configure Git accordingly:

$ git config --global fetch.prune true

Tags

Create and tag with a message

git tag -a 0.0.0 -m "initial Changelog" 
PreviousGitNextKnown Issues

Last updated 4 years ago

Was this helpful?