Files
lk/data/git.md

2.1 KiB

title, tags
title tags
git
data
setup
git config --global user.email "${email}"
git config --global user.name "${name}"

Decide on algorithm:

  • If you're scared of insecure hash-sums, go with hash=sha256.
  • If you don't know what a hash sum is, go with hash=sha1.

Init the Git

Start a git in directory ${DIR}:

git init --object-format=${hash} ${DIR}
cd ${dir}/

Make a file explaining what the project does, and tell git to track it:

echo "I hereby solemnly swear never to commit a binary file." > README.md
git add README.md

Then make the initial commit, explaining the change you just made:

git commit

Working

Once you make a change to some file, add it and make a commit explaining it.

git add ${file}
git commit -m"change ${file}"

Check your history:

git log

Remotes

If you want to keep a copy on a public site such as Gitlab, so others can see it, then go there and create a blank project (no readme, nothing). Give it the same name as the $DIR directory, above.

Add this as a remote:

remote=gitlab
git remote add ${remote}  https://gitlab.com/${username}/${dir}

Tell git you're pushing the branch 'master' to the remote repo 'origin':

git push -u master origin

Pull down changes that others have made:

git pull

Branches

A branch is a full copy of the project to test additional ideas. You can make a new branch called 'featurez' like this:

git branch ${feature_branch}

Have a look at all your branches:

git branch

Switch to your new branch:

git checkout ${feature_branch}

And if your changes are rubbish, checkout the "master" branch again, then delete "featurez":

git branch -D ${feature_branch}

Or if it's a good branch, push it to the remote:

remote=origin
git push $remote ${feature_branch}

Merging

Once you like the feature, merge it into the main branch. Switch to master then merge it:

git merge ${feature_branch}

And delete the branch, as you've already merged it:

git branch -d ${feature_branch}