Git commands overview. Git working ways. Git vs svn commands comparison.

In this article I am going to describe the basic approaches in working with git and basic commands git versus svn subversion systems.

Author: Sergey Taraban

:ad:

Svn vs git commands comparison

Table of svn and git commands comparison.

SVN

Git

Overview

svn update

git pull --rebase

Get latest changes from remote repository

svn revert -R

git checkout . or git checkout -- .

Revert all upstaged changes.

git reset --hard origin/

Full revert. Make your local repository the same as remote. If you had some unpushed commits this command would remove them.

svn commit –m””

svn delete

git add -A .

git commit -m””

git push orign

Commit the changes to the local repository and then push to the remote repository.

svn co [folder]

git clone [folder]

Create local git repository based on remote repository

svnstatus

git status

Information about local repository.

svn log

git log --oneline

Show log by one line

svn add

git add -a .

Add all files for commit: deleted, changed or new

svn delete --keep-local svn rm --keep-local

git reset

Remove file or folder from index

Unsupported

git clean -f

Delete all untracked files

svn update -r

git checkout

Go to commit with hash

-

git checkout

Take back

svn remove

git rm [filename]

Delete file and add him for commit (to commit list)

svn pedit svn:ignore .

Create file .gitignoreв in root folder of repository. Then add there a relative path to the file or folder that you want to add to ignore list.

Add file to ignore list

Git ways to work.

There are several work approaches or work rules when working with git. Each of these rules are easily combined with each other.

1. SVN way

This git approach is very similar to working with SVN version control system. Since git is a distributed system, we formally have two repositories - local and remote (origin). All commits we do in our local repository my commit command, and then we do sync repository with a remote by command pull --rebase.

Parameter –rebase brings our commit on the very top of the commits stack, making it the most important. This may produce some conflicts that are usually easily to resolve. Be careful when use merge tool. Is this case Theirs files - it is your changes, and Mine files - files from remote repository.

After this actions we need to synchronize our local repository with remote by using command git push origin, where branch - is out current working branch. If you did not make any new branches it would be default branch - master.

2. Stash way

Working through the stash buffer.

Git stash buffer - is a feature that allows you to hide your changes from the file system.

How it works. Let’s say you have made changes to the files and want to pull latest version of the source code from a remote repository. But you can not do pull –rebase, because you have modified files (uncommitted changes). For pull up a new version of files you need either make a commit, or “hide” your modified files.

git stash

This command will hide all that was added to the index. If you want to hide untracked files, you need to perform command git add before running stash command.

Now you get a clean repository and can now be done pull –rebase.

After pull you can return your change from stash by command git stash pop or git stash apply The difference in the commands is that the first clear the stash, and the second is not. So you can use stash buffer like back up. Since stash is a stack-based buffer, it can save a lot of changes.

In depth: git help stash

3. Git branching

This approach lies in the fact that any new feature that you implement, or bug that you fix must be in a separate branch. When a fix or a feature is finished, you make merge this branch in master. Using this approach strongly recommended working in different files and folders for each branches to avoid merge conflicts.

git branch - create new branch git checkout - switch to new branch git push origin - push in the new brunch at the remote repository will create our brunch there git branch -a - list of all brunches what we have at this moment. Our current branch is highlighted by green colour. Current branch also shoved git status command.

If you make a mistake you can delete or rename a brunch: git branch -d - delete brunch git branch -m - rename brunch

For example, we need the latest files from the brunch master. Merge our branch with with brunch master. git checkout master- switch to master git pull –rebase - update master to latest changes git checkout [our_branch] - switch back to out branch git merge master - get changes from master to our branch

Then we made some changes, fix bugs or implement feature for exemple. So now we need to upload out changes to master. git checkout [our_branch] - switch to out branch if we not there already git pull –rebase - update it to latest changes git checkout master - switch to master git pull –rebase - update master to latest changes git merge [our_branch] - merge our changes to master Merge commit will be created automatically. So the last things you need to push your changes to remote repository: git push origin master .

Author: Sergey Taraban