Design a site like this with WordPress.com
Get started

(My personal) git cheat sheet

Create a repository from existing code and push it to remote

Change into your code sub-directory and do:

git init
git add .
git commit -m "First commit"
git remote add origin https://REMOTE_HOST/REPO_NAME.git
git push -u origin master

Change a repositories origin remote url

This is useful if you have cloned a remote repository, change it and now want to commit it to your fork. Change into your code sub-directory and do:

git remote set-url origin https://REMOTE_HOST/REPO_NAME.git

Add a remote repository as a submodule

Change into the master repository directory and do:

git submodule add https://REMOTE_HOST/REPO_NAME.git REPO_NAME

If you have an older version of git and the REPO_NAME folder is empty, you need to initialize the submodule:

git submodule update --init --recursive

Remove a submodule

Change into the master repository directory and do:

git submodule deinit -f path/to/submodule
rm -rf .git/modules/path/to/submodule
git rm -f path/to/submodule

Adding a tag and pushing it to a repository

git tag -a TAGNAME -m "Tag title"
git push origin TAGNAME

TAGNAME can be a string or version number like “1.0”.


Merge upstream repository into fork (e.g. after accepted pull-request)

git checkout BRANCH_NAME
git pull https://REMOTE_ORIGIN/REPO_NAME.git BRANCH_NAME

Retains commit history without modifications. If this comes from an accepted pull request and the code does not differ from from your fork, then there should not be any conflicts and there’s nothing to commit. Else first resolve conflicts, commit and push the changes.

git push origin BRANCH_NAME

See also here.

Ignore an already commited / tracked file

Adding the file / directory to .gitignore only is not enough, but git will allow you to manually “ignore” changes to a file / directory:

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

And if you want to start tracking changes again, you can undo the previous command using:

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

Found here.

Advertisement

Published by HorstBaerbel

Software developer by trade and interest, but I venture into the electronics- and diy-world from time to time.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: