Nethence Newdoc Olddoc Lab Your IP BBDock  

Setting up & operating GIT repositories

Basic setup

cd git_repo/
git config user.name
git config user.name "your name"
git config user.email
git config user.email "your@email"
git config --global push.default simple
git config --global core.editor vim

ref.

alternate way,

git config --global --edit
#git commit --amend --reset-author

Create simple local repo

    cd somefolder/
    git init

Basic usage

review the files that have been changed and commit,

git status
git commit -a

review what is going to be pushed and push,

git diff --stat --cached origin/master
git push

Create real (bare) repo that will be used remotely only

as git user on the GIT server,

    mkdir project.git/
    cd project.git/
    git init --bare

Using Github

Quoting Github’s repo startup doc,

echo "# doc" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:elge9/doc.git
git push -u origin master

…or push an existing repository from the command line

git remote add origin git@github.com:elge9/doc.git
git push -u origin master

Once your repo is up and running you can then fetch it using git-clone e.g.,

#git clone https://github.com/pbraun9/doc.git
git clone ssh://git@github.com/pbraun9/doc.git
#git clone git@github.com:pbraun9/doc.git

Fetch a remote repo

from a workstation or some server,

    git clone ssh://git@gitsrv/home/git/project.git

and if you are using Github or Gitlab, HTTP(S) is also available,

git clone https://github.com/pbraun9/doc.git
    git clone http://git@gitsrv/home/git/project.git

Fix commit message(s)

refs.

Push to a remote repo after you started already

you can also create your own,

    cd project/
    git init
    git add *
    #git add --all
    git commit -m MESSAGE

and sync with the remote repo afterwards,

    git remote add origin ssh://git@gitsrv/home/git/project.git
    #git config --global push.default simple
    git push
    #git push --set-upstream origin master

Create your own branch

first, choose the branch you want to pick from,

    git checkout release-1

then create yours,

    git branch release-1-with-my-feature
    git checkout release-1-with-my-feature

finally commit and eventually push your changes.

Merge changes

create a minor branch against release v1 for you and others to commit,

    git checkout release-1
    git branch release-1.1.0
    git checkout release-1.1.0

merge your changes into the new minor branch,

    git merge release-1-with-my-feature

Note. merge --no-ff if you like.

Deploy apps

update the list of branches and switch to the new minor branch,

    git fetch -a
    git checkout release-1.1.0
    #git pull

and restart the application.

Misc

to loose track of a git folder and work on it without commiting the changes,

cd git_repo/
git rm -r --cached folder/
git commit -m "Removed folder from repository"
git push origin master

ref. http://stackoverflow.com/questions/6313126/how-to-remove-a-directory-from-git-repository

on Github you may check your SSH keys' by fingerprint,

ssh-keygen -E md5 -lf ~/.ssh/id_rsa.pub

Handy tweaks

for docs, scripts & configs you do not want to track like hell,

    git config --global alias.nc 'commit -a --allow-empty-message -m ""'

Troubleshooting

If you got this error,

error: Pull is not possible because you have unmerged files.

==> edit the file to proceed with the manual merge (see >>>>> lines…) and then,

git add merged_manually_file
git commit -m "manually merged"

Ref. http://stackoverflow.com/questions/26376832/why-does-git-say-pull-is-not-possible-because-you-have-unmerged-files

Take over a broken local repo (commit during battery fallout):


Home | GitHub | Donate | Contact