Skip to content

Latest commit

 

History

History
187 lines (135 loc) · 4.03 KB

git.md

File metadata and controls

187 lines (135 loc) · 4.03 KB

Git snippets

Create a new repo

git init

Clone new repo

git clone /path/to/repository
## OR:
git clone username@host:/path/to/repository

Add & commit local files to remote repo

Add changes to staging area

git add file.c

If you want to add all files in one rush, run:

git add .

⚠️ This adds all (!) files to the staging area without any check. Make shure that there are no sensible files uploaded mistakenly!

Then, if you added the file(s), run

git commit -m "Commit-Message"

to put the files to the git HEAD. To finally push the files to the remote repo, run:

git push origin branch_name

Connect your (new) local repo with existing online-repo

git init
git remote add origin <server>

Discharge local changes and pull and overwrite things from git

git checkout filename.xyz
git pull

Discharge local branch and reset to remote head

git fetch origin
git reset --hard origin/master

Switch off gpg signing

git config --global commit.gpgsign false

Change Username and E-Mail

git config user.name "new_username"
git config user.email "[email protected]"

Add new branch

git checkout -b name_of_new_branch
git push origin name_of_new_branch

Clone a specific branch only

git clone --single-branch --branch BRANCHNAME REPO_URL

New tag

  1. Add, commit and push new stuff

  2. If you want to replace an existing tag, delete the local tag:

    git tag -d v0.0.6
  3. Push deleted tag:

    git push -d origin v0.0.6
  4. New local tag:

    git tag -a v0.0.6 -m "release v0.0.6"
  5. Push local tag

    git push origin v0.0.6
  6. Merge the new date/state to all necessary branches

    ## Merge the status of the development branch into the master:
    git checkout master
    git merge development
    git push
    
    ## Merge the (new) status of the master branch also into the latest branch:
    git checkout latest
    git merge master
    git push origin latest

Archive a branch

git tag archive/BRANCHNAME BRANCHNAME
git branch -d BRANCHNAME
git checkout master

Get current repo url

git remote get-url --all origin

New repo-url to existing local repo

git remote set-url origin https://git.company.com/path/to/your-project.git

Sync local tags with remote (this overwrites local tags)

git tag
git fetch --prune-tags -f
git tag

Solve push declined due to email privacy restrictions error

To get your anonymous E-Mail address, read this answer on Stackoverflow: https://stackoverflow.com/a/44099011/13890903

git config user.email {ID}+{username}@users.noreply.github.com
git commit --amend --reset-author
git push