Git

From My Wiki
Jump to: navigation, search

Git is a distributed version control and source code management (SCM) system. It was created and used by the developer of Linux in developing Linux.

I use self-hosting GitLab

My first commands

Create a new repository on the command line

mkdir helloworld
cd helloworld
git init
touch README
git add README
git commit -m "first commit"
git remote add origin root@10.10.10.10:/home/git/repositories/root/helloworld.git
git push -u origin master

Push an existing repository from the command line

git remote add origin root@10.10.10.10:/home/git/repositories/root/helloworld.git
git push -u origin master

To remove a remote from your local repository, use the git remote rm command:

git remote -v
# View current remotes
# origin  git@github.com:user/repo.git (fetch)
# origin  git@github.com:user/repo.git (push)
# destination  git@github.com:forker/repo.git (fetch)
# destination  git@github.com:forker/repo.git (push)
git remote rm destination
# Remove remote
git remote -v
# Verify removal
# origin  git@github.com:user/repo.git (fetch)

To take a look at changes before commiting.

git diff 

Branching

git branch testing 
git checkout testing (-b will switch to it immediately, -d for delete)
git commit -a -m 'made a change'
git checkout master

git commit -a means almost[*] the same thing as git add -u && git commit.

It's not the same as git add . as this would add untracked files that aren't being ignored, git add -u only stages changes (including deletions) to already tracked files.

[*] There's a subtle difference if you're not at the root directory of your repository. git add -u stages updates to files in the current directory and below, it's equivalent to git add -u . whereas git commit -a stages and commits changes to all tracked files.

git merge testing

See also:

GitLab