Skip to content
This repository was archived by the owner on Apr 26, 2023. It is now read-only.

HowToGit

Pablo Conesa edited this page Nov 23, 2015 · 29 revisions
Scipion Logo

Basic GIT documentation

Configuration

Setup your name and email

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Setup some aliases

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status

Branches

List all branches:

 git branch -a

Create a new branch and move to it:

 git checkout -b NEW_BRANCH

Then you can publish it to origin:

 git push -u origin NEW_BRANCH

Deleting a branch

Locally delete a branch

 git branch -d OLD_BRANCH
This must be done in a different branch than OLD_BRANCH

The previous command does not allow to locally remove unless the OLD_BRANCH has been merged to another branch. If you want, anyway to locally remove the branch do

 git branch -D oldBranch

To delete the branch remotely (after delete it locally):

 git push origin :OLD_BRANCH

Everybody else has to "update" the list of branches in the origin, so that they also get it deleted:

 git remote prune origin

Remote branch

To create a local branch at the status of a remote branch:

git pull
git checkout -b newlocalbranchname origin/remotebranchname

To create a branch and also set to track the remote branch:

git pull
git checkout -t origin/branch-name [-b newlocalbranch]

Compare differences

To see differences between branch A and B:

git diff --name-status A..B

Tags

To create a tag:

git tag -a TAG_NAME -m "TAG MESSAGE"

You can submit to a shared server in the same way as a branch:

git push origin TAG_NAME

Stashing

Often, when you’ve been working on a part of your project, things end in a messy state. You want to switch branches for a while in order to work on something else. The problem is, you don’t want to do a commit of half-done work (just to be able to get back to this point later). The answer to this issue is the git stash command:

$ git stash

Now you can easily switch branches and do work elsewhere: your changes are stored on your stack. To see which stashes you’ve stored, you can use:

git stash list:

You can reapply the one you just stashed by using the command shown in the help output of the original stash command:

git stash pop

Merging

Undo a merge in the middle of it

Let’s say you are in the middle of a merging, and you regret from the changes you have already been introducing. Files that are not related to the merging conflicts are unaffected by this command.

git merge --abort

Commits and differences

Checkout a commit by date

In case of looking for a commit by date, the repository can be moved by:

git co `git rev-list -n 1 --before="2011-06-21 13:37" master`

Check which commits have not been pushed yet

git log origin/master..master

List the files that are changed between the local and the official

repository

git diff origin/branch --name-only

List the files that are changed between two branches

git diff branch1 branch2  --name-only

Other useful commands

git grep
  • Look for specified patterns in the tracked files in the work tree.

git blame
  • Show what revision and author last modified each line of a file.

Clone this wiki locally