Difference between revisions of "Working with Git"

From Inkscape Wiki
Jump to navigation Jump to search
Line 89: Line 89:


Another difference is that in Git, you cannot directly make changes to remote branches - you must to use <code>git push</code> and <code>git pull</code>. Therefore, the Subversion-like checkout mode known from Bazaar is unsupported.
Another difference is that in Git, you cannot directly make changes to remote branches - you must to use <code>git push</code> and <code>git pull</code>. Therefore, the Subversion-like checkout mode known from Bazaar is unsupported.
===Other cheatsheets===
* [http://rogerdudler.github.io/git-guide/ git - the simple guide] - short and sweet, enough to get started

Revision as of 21:54, 3 June 2017

This page contains an introduction to the Git distributed version control system. For now, it is mainly useful to Bazaar users, but will be updated with general Git information over time.


Git commands for the novice

  • git status — Returns status of your local repository.
  • git pull — Updates local repository from remote repository.
  • git pull --rebase — Updates local repository moving any local commits after any pulled commits. Good for keeping things in order when you push your commits.
  • git add — Add files to the list that will be commited.
  • git commit — Commit your changes locally (after adding).
  • git push — Push your locally commited changes to remote repository.
  • git remote -v — Shows remote repository (should be: origin https://git_to_be_determined).
  • git checkout filename — Reverts 'filename' to repository version.
  • git stash — Move changes in directory out of the way (in order to 'pull' in changes).
  • git stash pop — Restore changes stashed by 'git stash'.

Cheat sheet for Bazaar users

Bazaar command Git command
bzr branch branch-url git clone repository-url directory
cd directory
git checkout branch-name
bzr checkout lp:project-name not supported
bzr update not supported
bzr pull git pull
bzr add file git add file
bzr diff git diff HEAD
bzr revert git reset --hard
bzr revert file -r revision git checkout commit -- file
bzr uncommit git reset HEAD^
bzr uncommit
...some changes...
bzr commit
...some changes...
git commit -a --amend
bzr push location git remote add remote-name location
git push remote-name branch-name
bzr commit git commit -a
bzr log -c 10 git log -n 10
bzr switch branch-url git checkout branch-name
bzr switch -b branch-url git checkout -b branch-name
bzr merge branch-url git merge branch-name
bzr shelve --all git stash
bzr unshelve change-id git stash pop

Differences from Bazaar

Here are the most important differences between Bazaar and Git:

  • Bazaar revisions are identified by sequential numbers. Git revisions (called commits in the documentation) are identified by cryptographic hashes which are strings of 40 hexadecimal numbers, though it is possible to also refer to them by a sequential number since the last tag (see git describe).
  • Bazaar is branch-oriented, while Git is repository- and commit-oriented. Repositories in Bazaar are storage locations for potentially multiple branches. Repositories in Git are collections of commits, and branches are just pointers to particular commits that are updated after each git commit command. Cloning a Git repository by default retrieves all of its commits and branches.
  • In Bazaar, you conceptually submit your work to only one place - the push branch. You can change this place at any time, but Bazaar remembers only one value for you. In Git, you can configure many remote repositories and work with code from multiple sources using a single working tree.
  • By default, each branch in Bazaar has a separate working tree, while all branches in the same Git repository share the same working tree. It's possible to make Bazaar work in the latter mode as well, but it's not very well supported.

In Bazaar, if you want to try out someone else's code, you need to create a new checkout of their branch or use bzr switch. In Git, what you do depends on where the code is located.

  • If the code to try out is in a branch in the project's main repository, you update the repository (git fetch) and then check out the branch (git checkout origin/branch-to-try-out). This creates a local branch called branch-to-try-out. (You can use a different name as well.)
  • If the code is in a different repository, you first add it as a remote repository with git remote add remote-name repository-url, fetch it with git fetch remote-name and check out the relevant branch with git checkout remote-name/branch-to-try-out.

Another difference is that in Git, you cannot directly make changes to remote branches - you must to use git push and git pull. Therefore, the Subversion-like checkout mode known from Bazaar is unsupported.

Other cheatsheets