Git

Introduction

In GIT you can have multiple repositories.
A classical example is 1 remote repository, to which all the developers push.
Every developer also has a local repository. This is usually in the working directory.

To know the remote repositories:
git remote -v
This will show the name and url of the remote repositories. The default name of a remote repository is origin.

Git clients

https://git-scm.com/download/gui/windows
- Git GUI (comes default with GIT)
- Tortoise Git
- Smart Git
- Source Tree
- GitKraken
- Visual Studio

Git workflows

GitHub Flow
Too simple. Just check pull request.
GitFlow
GitLab Flow

Convert a SVN repository to Git

Convert the repository

If the you have a local SVN repository, you need to expose it by the svn: protocol. You can do this with svnserve:

svnserve.exe -d -r pathToMyLocalSvnRepositories

By default, the username of SVN will be taken. This means it won't have an email. In Git, a user normally has an email.
So if you push to a server like eg. VSTS, this system will create a virtual email address for you.
If you want to manage the users for Git, you first need to extract the SVN users, first extract all the users of the commits.
Execute next line in Git Bash:
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt
The users will now be in the authors-transform.txt file like name = name <name>
Edit this file so you have the descriptions you want like name = full name <moc.liam|eman#moc.liam|eman>

Then clone the svn repository to Git:
Without authors file:

git svn clone svn://localhost/myLocalSvnRepository --no-metadata --stdlayout pathToMyNewGitRepository

With authors file:
git svn clone svn://localhost/myLocalSvnRepository --no-metadata -A authors-transform.txt --stdlayout pathToMyNewGitRepository

The tag —stdlayout means you have a classical SVN setup with tags, branches and trunk folders. It is possible to change this.
Normally, the SVN trunk will be renamed to the Git master.

https://john.albin.net/git/convert-subversion-to-git

Push to your remote repository

For creating a bare remote repository in VSTS, see Varia - Visual Studio Team Services.

git remote add origin https://{account}.visualstudio.com/DefaultCollection/_git/{name repository}
git push -u origin --all

I noticed in this way the tags aren't shown in VSTS.
Maybe you need to do also
git push origin master —tags?

Daily use

https://githowto.com/

git config —global user.name "Your Name"
git config —global user.email "moc.revetahw|liame_ruoy#moc.revetahw|liame_ruoy"

git add hello.html : stage the file hello.html
git commit -m "First Commit" : commit the staged files to the repository with the message "First commit".
git status : shows the current status of the local repository.
git checkout: undo changes

Copying changes to a repository

Git Commit …: Copies the made changes to the local repository.
Push: Copies all the changes committed to the local repository, to the remote repository
Copying changes to a SVN repository: SVN DCommit

Getting changes from a (remote) repository

Pull will merge remote branch change to local branch which tracked with remote branch.
Fetch just get change from remote branch and never merge.
Getting changes from a SVN repository: SVN rebase

Remove tag

git tag -d release01
git push origin :refs/tags/release01

Undo local commits and go back to origin/master

git reset —hard origin/master

Revert a commit already pushed to a remote repository

http://christoph.ruegg.name/blog/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.html

Other commands

git init : create a new repository
git —version : shows the version of git you are using
git config —list : shows the Git configuration settings in a list

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License