Tips: More than 100 commands for GitHub / Git that you should know

Yesterday was quite a programming day and a conflict with the git repository led me to hemanth repository where I got a complete list with more than 400 commands guidance on GitHub / Git that are considered the most used, each of them is accompanied by an explanation of their use. If you have no idea what it is GitHub or you just had a problem installing it, you can go to Quick guide to using GitHub that will surely remove all your doubts.

Table of Contents

Git help for daily use, less than 20 commands to use git daily.

git help everyday

Show Git Help guide

git help -g

Overwrite pull

git fetch --all && git reset --hard origin / master

List of all files up to a commit

git ls-tree --name-only -r <commit ish>

Update the reference to the first commit

git update-ref -d HEAD

List of all files in conflict

git diff --name-only --diff-filter = U

List of all files changed in commit

git diff-tree --no-commit-id --name-only -r <commit ish>

See the changes you have made since the last commit

git diff

Compare your prepared changes with your last commit

git diff --cached

Shows the difference between logged and unrecorded changes

git diff HEAD

List all branches that have already merged with your master

git branch --merged master

Quickly switch to the previous branch

git checkout -

Remove the branches that have already been merged with the master

git branch --merged master | grep -v '^ \ *' | xargs -n 1 git branch -d

List all branches and their last commits with the branch

git branch -vv

Track the branch

git branch -u origin / mybranch

Delete a local branch

git branch -d <local_branchname>

Delete a remote branch

git push origin --delete <remote_branchname>

Undo local changes with the latest content in the head

git checkout - <file_name>

Roll back a commit by creating a new commit

go revert <commit ish>

Discard a commit, recommended only in private branches

git reset <commit ish>

Change the previous commit message

git commit -v --amend

Modify the Author

git commit --amend --author ='Author Name'

Reset the author, after the author has been changed in global settings

git commit --amend --reset-author --no-edit

Change the remote URL

git remote set-url origin <URL>

Gets a list of all remote references

git remote

Alternative:

git remote show

Get a list of all local and remote branches

git branch -a

Get a list of remote branches

git branch -r

Add the changed parts of a file, instead of the whole file

git add -p

Find completed attempts

curl http://git.io/vfhol > ~/.git-completion.bash && threw out '[-f ~ / .git-completion.bash] &&. ~ / .git-completion.bash' >> ~/.bashrc

Shows the changes of the last 2 weeks

git log --no-merges --raw --since ='2 weeks ago'

Alternatives:

git whatchanged --since ='2 weeks ago'

View all commits of the master forks

git log --no-merges --stat --reverse master ..

Selecting commits across branches using cherry-pick

git checkout <branch name> && git cherry-pick <commit ish>

Find the branches that contain commit hash

git branch -a --contains <commit ish>

Alternative:

git branch --contains <commit ish>

Git aliases

gitconfig --global alias.<handle> <command> 
gitconfig --global alias.st status

Quickly and provisionally save (stasheado) the work carried out

go stash

Alternative:

git stash save

Stasheado of all files, even those that are not prepared.

git stash save -u

Alternative:

git stash save --include-untracked

Show list of all stasheado files

git stash list

Use any staged change without deleting it from the staged list

git stash apply <stash @ {n}>
go stash pop

alternatives:

git stash apply stash @ {0} && git stash drop stash @ {0}

Delete all stored stashes

git stash clear

alternatives:

git stash drop <stash @ {n}>

Take a specific file that has been stashed

git checkout <stash @ {n}> -- <file_path>

Alternative:

git checkout stash @ {0} - <file_path>

Show all prepared files

git ls-files -t

Show all files that have not been prepared

git ls-files --others

Show all ignored files

git ls-files --others -i --exclude-standard

Create a new repository working tree (git 2.5)

git worktree add -b <branch name> <path> <start point>

Create a new working tree from a HEAD

git worktree add --detach <path> HEAD

Delete a file from the git repository without deleting it from the local repository

git rm --cached <file_path>

Alternative:

git rm --cached -r <directory_path>

Before deleting raw files, take a test drive to get the list of these files.

git clean -n

Force deletion of unprepared files

git clean -f

Force removal of unprepared directories

git clean -f -d

Alternative:

git clean -df

Update all submodules

git submodule foreach git pull

Shows all changes in the current branch that have not been merged with the master

git cherry -v master

Alternative:

git cherry -v master <branch-to-be-merged>

Rename a branch

git branch -m <new-branch-name>

Alternative:

git branch -m [<old-branch-name>] <new-branch-name>

Update 'feature' and make merged 'master'

git checkout feature && git rebase @ {- 1} && git checkout @ {- 2} && git merge @ {- 1}

Archive the master branch

git archive master --format = zip --output = master.zip

Modify the previous commit without modifying the report message

git add --all && git commit --amend --no-edit

Delete remote branches that no longer exist in origin

git fetch -p

Alternative:

git remote prune origin

Retrieve the commit hash from the initial revision

 git rev-list --reverse HEAD | head -1

View the version tree

git log --pretty = oneline --graph --decorate --all

Alternative:

gitk --all

Add a project to a repository using subtree

git subtree add --prefix =<directory_name>/<project_name> --squash git@github.com:<username>/<project_name>.gitmaster

Get the latest changes from your repository for a linked project using subtree

git subtree pull --prefix =<directory_name>/<project_name> --squash git@github.com:<username>/<project_name>.gitmaster

Export a branch and its history to a file

git bundle create <fillet> <branch name>

Import from a bundle

git clone repo.bundle <repo-dir> -b <branch name>

Gets the name of the current branch

git rev-parse --abbrev-ref HEAD

Ignore a file that has already been committed (eg Changelog).

git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog

Stashea changes before rearranging

git rebase --autostash

Search by id in local branch

git fetch origin pull /<id>/ head:<branch name>

alternatives:

git pull origin pull /<id>/ head:<branch name>

Shows the most recent tags of the current branch

git describe --tags --abbrev = 0

Look for differences.

git diff --word-diff

Ignore changes to the trace file

git update-index --assume-unchanged <file_name>

Undo

git update-index --no-assume-unchanged <file_name>

Clean up files .gitignore.

git clean -X -f

Restore deleted file.

git checkout <deleting_commit>^ - <file_path>

Restore files with a specific commit-hash

git checkout <commit ish> -- <file_path>

Always rearrange instead of merge

git config --global branch.autosetupprebase always

List all aliases and settings

git config --list

Make case git sensitive

git config --global core.ignorecase false

Types of self-correction.

gitconfig --global help.autocorrect 1

Checks if the change is part of a release.

git name-rev --name-only <SHA-1>

Clean Dry run.

git clean -fd --dry-run

Mark the commit as a solution to the previous commit

git commit --fixup <SHA-1>

Squash correction

git rebase -i --autosquash

Skip staging area during commit.

git commit -am <commitmessage>

List the ignored files

git check-ignore *

Status of ignored files

git status --ignored

Commits in Branch1 that are not in Branch2

git log Branch1 ^ Branch2

save and reuse previous conflict resolutions

git config --global reference.enabled 1

Open all conflicting files in an Editor.

git diff --name-only | unique | xargs $ EDITOR

Count the number of unprepared objects and their consumption on disk.

git count-objects --human-readable

Maintenance of inaccessible objects

git gc --prune = now --aggressive

Instantly view your repository on gitweb.

git instaweb [--local] [--httpd=<httpd>] [--port=<port>] [--browser=<browser>]

View GPG signatures in the confirmation log

git log --show-signature

Removes entries from global settings.

git config --global --unset <entry-name>

Get a new branch with no history

git checkout --orphan <branch_name>

Displays the difference between the production file and the latest version of the file.

git diff --staged

Extract a file from another branch.

git show <branch_name>:<file_name>

List only the root and confirm the merge

git log --first-parent

Merge between two commits

git rebase --interactive HEAD ~ 2

List all branches

git checkout master && git branch --no-merged

Find using binary search

git bisect start git bisect bad git bisect good v2.6.13-rc2 git bisect bad git bisect good git bisect reset                    

List the commits and changes of a specific file

git log --follow -p - <file_path>

Clone a single branch

git clone -b <branch name> --single-branch https://github.com/user/repo.git

Create and switch to a new branch

git checkout -b <branch name>

Ignore files that have changes in commits

git config core.fileMode false

The content of the article adheres to our principles of editorial ethics. To report an error click here!.

2 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Gabriel said

    Excellent compilation of commands 😉

  2.   Jesus Perales said

    Excellent contribution !!