Skip to content

Instantly share code, notes, and snippets.

@digitalkreativ
Last active April 19, 2024 09:00
Show Gist options
  • Save digitalkreativ/a5a3d1ee2ebe73c6111746f464033706 to your computer and use it in GitHub Desktop.
Save digitalkreativ/a5a3d1ee2ebe73c6111746f464033706 to your computer and use it in GitHub Desktop.
Git commands #git #dev
# All files excluded
/**
# except gitignore
!.gitignore
# except default folder
!/_default/
# except default sub folders
!/_default/**

Git commands

Some usefull git commands you can use

List branches without pager

git --no-pager branch

History of git commits

git log

This displays the commit, date, user, message. Press arrow up / down to move through the list. Press q to quit.

Download repository as archive

Bitbucket

git archive --remote=ssh://git@bitbucket.org/<user>/<repo>.git --format=zip --output="<archive>.zip" <branch>

List all files inside a commit

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

Used in combination with the git log command you can check which files were changed in a specific commit.

Remote info

If you want only the remote URL:

git config --get remote.origin.url

If you require full output or referential integrity is intact:

git remote show origin

When using git clone (from GitHub, or any source repository for that matter) the default name for the source of the clone is "origin". Using git remote show will display the information about this remote name. The first few lines should show:

$ git remote show origin
* remote origin
  Fetch URL: git@github.com:jaredpar/VsVim.git
  Push  URL: git@github.com:jaredpar/VsVim.git
  HEAD branch: master
  Remote branches:

Stash

Sometimes you work on something and realise your on the wrong branch or need to fix something in your current branch and push that to your remote repository. This is where git stash comes in. With this command you can track your current file state (with their changes) and reapply them at a later stage.

To start off use:

git stash

Later on you can just use the following command to apply the latest stash

git stash apply

You can also verify if you have multiple stashes

git stash list

This will result in a list with all your stashes like below

stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051 Revert "added file_size"
stash@{2}: WIP on master: 21d80a5 added number to log

Listing the changed files can be done with

git stash show stash@{1}

Dropping a stash can be done with

git stash drop stash@{1}

More information can be found at the Git documentation

Stash with a custom message can be accomplished with

git stash save your custom message can be set here

Key part here is the save key word to set your custom message

How to delete remote tags

https://stackoverflow.com/questions/5480258/how-to-delete-a-remote-tag

You just need to push an 'empty' reference to the remote tag name:

git push origin :tagname

Or, more expressively, use the --delete option (or -d if your git version is older than 1.8.0):

git push --delete origin tagname

If you also need to delete the local tag, use:

git tag --delete tagname

Background Pushing a branch, tag, or other ref to a remote repository involves specifying "which repo, what source, what destination?"

git push remote-repo source-ref:destination-ref

A real world example where you push your master branch to the origin's master branch is:

git push origin refs/heads/master:refs/heads/master

Which because of default paths, can be shortened to:

git push origin master:master

Tags work the same way:

git push origin refs/tags/release-1.0:refs/tags/release-1.0

Which can also be shortened to:

git push origin release-1.0:release-1.0

By omitting the source ref (the part before the colon), you push 'nothing' to the destination, deleting the ref on the remote end.

Github stuff

If you want to start helping with open source software you will most likely fork a repository on github and start working on it. That fork is now a snapshot of the current state of that repository. Changes to the original repository will not automatically be synced to your fork. To enable you to update your fork you need to set up some things first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment