Eric J Ostrander's

ClearCase / ClearQuest / Git/Stash "how to" pages.

Git, how do I ...


CLI commands that are for Stash require a separate install of the CLI.
https://marketplace.atlassian.com/plugins/org.swift.stash.cli
Branches   |   Files   |   Hooks   |   Misc.   |   Repositories   |   Stash   |   Tags   |   Users & Groups

This page is my own personal work. Anyone can use it for their own edification, but must realize that this material is not supported by me and the site is not affiliated with IBM Rational Software or Atlassian.



Branches
Back to the TOP
Create a new branch.
Switch branches (checkout).
Merge branches.
Veiw branch history.
Push a branch to a remote repository.

Files
Back to the TOP
Add a file to source control; tracking
Merge a single file.
Ignore certain untracked files.
Automatically commit unstaged changes.
Remove a file from tracking.
Rename a file.
Unstage a change.
Revert a file to what is in the repository.
View commit history.
Stage changes.
Push committed changes to the central repository.
Add files with very long paths.

Hooks
Back to the TOP
Create a hook.
Centralize the management of hooks.

Misc.
Back to the TOP
Get the current status of changes and staging.
Set global configs.
Git interfaces, front-ends, and tools.
Get command help.
Implement a Git commit message template.
Change where Git finds your home directory.
Set a Git config that gets inherited by all clones.

Repositories
Back to the TOP
Create a repository.
Clone (copy) a repository.
Determine if a repository is bare.
Link to a remote repository.
Delete a repository.
Change the URL associated with a remote repository.
Fork a repository.

Stash
Back to the TOP
Find where Stash is installed.
Locate where Stash stores repositories.
Uninstall Stash.

Tags
Back to the TOP
Create a tag.

Users & Groups
Back to the TOP
Create a user in a Stash instance.
Create a Stash group.
Add a group to a repository.
Reset a user's password.
Remove a group from a project.




Create a new branch.
Updated: 07/24/14
Version: 1.9.4

GUI
Unknown if it's possible.

CLI
	git branch branch-name
Table of Contents



Switch branches (checkout).
Updated: 07/24/14
Version: 1.9.4

When you switch branches (checkout a branch) the content of visible files is changed.

GUI
Branch -> Checkout

CLI
	git checkout branch-name
Table of Contents



Merge branches.
Updated: 07/24/14
Version: 1.9.4

If there are merge conflicts in a file, the file can be edited in a text editor. The file currently fetched will have the merge information from both contributors.
GUI
Merge -> Local Merge

CLI
This will merge branch-name to master. It's unknown how to merge two arbitrary branches ... yet.
	git merge branch-name
Table of Contents



View branch history.
Updated: 07/22/14
Version: 1.9.4

GUI
Repository -> Visualize branch-name|All branch History

CLI
	gitk
Table of Contents



Push a branch to a remote repository.
Updated: 07/22/14
Version: 1.9.4

GUI
Remote -> Push

CLI
	git push remote-name branch-name

	Ex:
	git push origin master
Table of Contents



Add a file to source control (tracking).
Updated: 08/19/14
Version: 1.9.4

GUI
1) Rescan
2) Stage Changes (yes, stage the untracked files)
3) Commit

CLI
The file must already exist to add it to source. That is, you can't initiate the creation of a file at the same time as adding it to source. If file is actually a folder, Git will automatically recursively add the entire folder tree to source control. However, Git doesn't appear to track versions of folders, so only files in the tree are added.
	# Single file
	git add file

	# All files, as when you initialized the repository's content.
	git add --all
	-or-
	git add .


	git commit
After adding a file to source control, it's said to be "tracked".

Table of Contents





Merge a single file.
Updated: 07/24/14
Version: 1.9.4

Unknown if it's possible ... yet.

Table of Contents





Ignore certain untracked files.
Updated: 07/28/14
Version: 1.9.4

When staging files Git will prompt you regarding untracked files that present. You can instruct Git to ignore certain files, or classes of files, that will never be added to source control (tracked).

Create a .gitignore file in the top level of the repository, above the .git folder.
Each line in the file is a simplified regular expression, such as the following.
	# Use pound signs to add comments.
	*.jar	# Ignore all .jar files.
	*.[oa]	# Ignore all files ending .o or .a.
	!*.c	# Ignore all files expect .c files (negation).
See "git --help gitignore" for more information.

Table of Contents





Automatically commit unstaged changes.
Updated: 08/18/14
Version: 1.9.4

It's possible to bypass the staging phase before committing a change. The changes need to already be in tracked files.

GUI
Unknown if it's possible.

CLI
The -a option tells git to simply take all changes without staging them.
	git commit -a -m commit-message
Table of Contents



Remove a file from tracking.
Updated: 07/29/14
Version: 1.9.4

If you manually remove a file from your working area, it will then need to be staged as a change and then committed.

GUI
Unknown if it's possible ... yet.

CLI
The rm subcommand removes the file and stages the change.
	git rm file

	# Leave the file in your working tree, but stop tracking.
	git rm --cached file
Table of Contents



Rename a file.
Updated: 07/29/14
Version: 1.9.4

GUI
Unknown if it's possible ... yet.

CLI
	git mv old-name new-name

	# This is the same as:
	move/mv old-name new-name
	git rm old-name
	git add new-name
Table of Contents



Unstage a change.
Updated: 07/29/14
Version: 1.9.4

GUI
Select the file with the changes to be unstaged.
Commit -> Unstage From Commit

CLI
	git status
	git reset HEAD file
Table of Contents



Revert a file to what is in the repository.
Updated: 07/29/14
Version: 1.9.4

GUI
Unknown if it's possible ... yet.

CLI
	git checkout file
Table of Contents



View commit history.
Updated: 07/29/14
Version: 1.9.4

GUI
gitk

CLI
Type "q" to exit viewing the log.
NOTE: On Windows, if you use CTRL-C to exit, it won't exit and then won't accept the "q" to quit.
	git log
Git log has a large number of options for parsing and viewing the log. Some useful ones are:
--since # Get logs since a certain date/time.
--author # Gets changes made by a give user.
--grep # Look for keywords in the commit entries.

Table of Contents





View commit history.
Updated: 08/19/14
Version: 1.9.4

GUI
1) Start -> Programs -> Git -> Git GUI
2) Open an existing repository.
3) Click "Stage Changed" near the bottom.

CLI
Unknown if it's possible ... yet.

Table of Contents





Push committed changes to the centrol repository.
Updated: 09/05/14
Version: 1.9.4

The following assumes a remote repository has been specified.

GUI
1) Start -> Programs -> Git -> Git GUI
2) Open an existing repository.
3) Click "Push" near the bottom.

CLI
	git remote --verbose
	git push remote-repo-name branch
Table of Contents



Add files with very long paths.
Updated: 09/05/14
Version: 1.9.4

CLI
	git config --global core.longpaths true
Table of Contents



Create a hook.
Updated: 09/16/14
Version: 1.9.4

If the hook is written in Bash, the shebang only needs to point to "/bin/sh" on Windows. Git knows where to find the sh executable under its install path.
If the hook script doesn't have a specific executable extension, Git assumes a Bash script.
Hook scripts must be in the ".git/hooks" folder of the repository.
Hook scripts do not get copied to a cloned repository. That is, there is no built-in way to centralize the management of the hooks such that any hook changes are automatically picked up by all the cloned repositories.
If you want to write your hooks in Perl, simply use a "#!/bin/perl" shebang line. There is a Perl executable bundled with the Git install, but note that it doesn't have very many libraries. Don't add a ".pl" extension to the hook script.
Any file that is executable and has a Git hook name in the ".git/hooks" folder will be executed at the appropriate time.
Full list of Git hooks: https://www.kernel.org/pub/software/scm/git/docs/githooks.html
Customizaing Git hooks: http://git-scm.com/book/en/Customizing-Git-Git-Hooks

Table of Contents





Centralize the management of hooks.
Updated: 09/19/14
Version: 1.9.4

Hook scripts do not get copied to a cloned repository. That is, there is no built-in way to centralize the management of the hooks such that any hook changes are automatically picked up by all the cloned repositories.

Table of Contents





Get the current status of changes and staging.
Updated: 07/24/14
Version: 1.9.4

GUI
Rescan

CLI
	git status
Table of Contents



Set global configuration information.
Updated: 09/17/14
Version: 1.9.4

The term "global" is a bit misleading. Global means that the parameter applies to all of your local repositories. The change doesn't apply to other user on the same computer (unless you use --system), nor does the change apply to the central repository from which you got your clone.
Personal global config information is stored in a .gitconfig file in your home directory, so is used on any computer where that home directory is used.

Some useful global configs:
	git config --global user.name "Your Full Name"
	git config --global user.email you@yourdomain.example.com
	git config --global core.longpaths true
Table of Contents



Git interfaces, front-ends, and tools.
Updated: 07/24/14
Version: 1.9.4

See https://git.wiki.kernel.org/index.php/InterfacesFrontendsAndTools

Table of Contents





Get command help.
Updated: 07/28/14
Version: 1.9.4

GUI
Even though the menu says "Online Documentation", the man pages are actually part of the local install.
Help -> Online Documentation

CLI
Note that help is available for topics that aren't commands. For example you can get help on the .gitignore file by specifying "gitignore" as the command.
	git --help command
Table of Contents



Implement a Git commit message template.
Updated: 09/24/14
Version: 1.9.4

Adding a commit message entails editing the the ".git/hooks/pre-commit-msg" bash script. The prepare-commit-msg hook is run before the commit message editor is fired up, but after the default message is created. It lets you edit the default message before the commit author sees it.
Note that the commit message file only gets created once from the Git GUI. That is, if the file ".git/GITGUI_MSG" already exists, the pre-commit-msg hook script won't overwrite it. If you're troubleshooting the commit message template without actually performing a commit each time, you need to manually remove that file to see your hook script changes. Git deletes the GITGUI_MSG file when the commit is finished.

To make quality checks on the entered information, perhaps to ensure the user didn't change the template format, customize the "commit-msg" hook.

Table of Contents





Change where Git finds your home directory.
Updated: 09/17/14
Version: 1.9.4

By default on Windows, Git will write to C:\users\. You can set that folder some to some other place, such as a network drive, by setting a User Environment Variable called "HOME".

Table of Contents





Set a Git config that gets inherited by all Clones.
Updated: 09/18/14
Version: 1.9.4

If a repository has very long paths, the git config "core.longpaths true" needs to be set. The config parameter needs to be set every time by any user before getting a clone of the repository.
Unfortunately, it doesn't appear to be possible to set a config so that all clones automatically get that parameter. That is, it doesn't appear possible to attach the config to the repository itself; config items are written to local files not attached to a repository.

Table of Contents





Create a repository.
Updated: 07/24/14
Version: 1.9.4

The parent repository folder will contain the files being worked on and also a folder called ".git", which is everything is permanently stored. However, when Git ever asks for "the repository", it's referring to the parent folder of .git.
GUI
1) Start -> Git -> Git GUI
2) Create New Repository
repository-folder

CLI
	mkdir repository-folder
	cd repository-folder
	git init
Table of Contents



Clone a repository.
Updated: 09/23/14
Version: 1.9.4

Users should only clone from a bare repository; one that doesn't have a working directory or index (staging area). Set up the central repository as bare.

GUI
1) Start -> Git -> Git GUI
2) Clone Existing Repository

CLI
	git clone URL
The URL can be in the following forms:
git://site/repo-name.git
http(s)://site/repo-name.git
user@server:/scm/cm/repo-name.git
--local C:\gitirepository\.git clone-name

If you want to have the clone automatically checked out to a branch other than the default "master", add "-b branch".

Table of Contents





Determine if a repository is bare.
Updated: 08/07/14
Version: 1.9.4

Users should only clone from a bare repository; one that doesn't have a working directory or index (staging area). Set up the central repository as bare.

GUI
Unknown if it's possible ... yet.

CLI
Execute the command while sitting in the repository. It will return a simple "true" or "false".
	git rev-parse --is-bare-repository
Table of Contents



Link to a remote repository.
Updated: 09/05/14
Version: 1.9.4

The URL has the format "https://username@server:7990/scm/cm/repository-name.git".
	git remote add origin URL
Table of Contents



Delete a repository.
Updated: 08/18/14
Version: 1.9.4

Simply remote the ".git" folder.
If the repository is known by a name in other repositories.
	git remote set-url --delete repository-name-being-deleted URL
Table of Contents



Change the URL associated with a remote repository.
Updated: 08/18/14
Version: 1.9.4

	git remote set-url remote-repo-name "URL"
	git remote --verbose
Table of Contents



Fork a repository.
Updated: 09/12/14
Version: 1.9.4

A fork does not inherit repository level permissions (users and groups).
Stash has the option to keep the forked repository automatically synced with the original. However, while the documentation says the fork will stay in sync, it doesn't specify if changes in the fork are automatically synced back to the original.
Anyone with read access to a repository can fork it.
Forking can be disabled for a given repository.
Pre-receive hooks are not forked, so have to be implemented again for the new repository.

1) Log into Stash.
2) Enter the project and repository to be forked.
3) Click the Fork button in the upper-right corner.

Table of Contents





Find where Stash is installed.
Updated: 08/06/14
Version: 2.12.2

Some documentation states that there should be a $STASH_HOME environment variable present after installation, but I don't see one.
However, Stash installed itself as a service, so inspecting the properties of the "Atlassian Stash AtlassianStash" service gives install directory.
On my system, it was installed in "C:\Atlassian\Stash".

Table of Contents





Locate where Stash stores repositories.
Updated: 08/19/14
Version: 2.12.2

1) Go to the local Stash web site: http://ip-address:7990/projects
2) Locate the project and repository.
3) On the bottom-left of the page, click on Settings.

Table of Contents





Uninstall Stash.
Updated: 08/15/14
Version: 2.12.2

Stash can be uninstalled by locating it in the add and remove programs section of the control panel. There might be

Table of Contents





Create a tag.
Updated: 07/30/14
Version: 1.9.4

Git uses two main types of tags: lightweight and annotated. A lightweight tag is very much like a branch that doesnít change ó itís just a pointer to a specific commit. Annotated tags, however, are stored as full objects in the Git database. Theyíre checksummed; contain the tagger name, e-mail, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG). Itís generally recommended that you create annotated tags so you can have all this information; but if you want a temporary tag or for some reason donít want to keep the other information, lightweight tags are available too.

By default, the git push command doesnít transfer tags to remote servers. You will have to explicitly push tags to a shared server after you have created them. This process is just like sharing remote branches ó you can run "git push remote tagname".

Creating the tag automatically associates it with the latest version of all files visible in the current branch.

GUI
Unknown if it's possible ... yet.

CLI
	# Lightweight
	git tag tag-name

	# Annotated
	git tag -a -m "comment" tag-name
Table of Contents



Create a user in a Stash instance.
Updated: 09/11/14
Version: 3.9.0

User names and passwords are local to the Stash instance, so can be anything. There is no password strength enforcement or expiration date.
WARNING: If you create the user programmatically using the stash CLI interface, there is no way for the user to reset their own password if you leave it blank. That is, if you don't set the password to a non-null value during the addUser action, the user will be unable to login to change it. By comparison, when you create a user in the web interface, you must either send the user an email with an encoded temporary password asking them to reset their own password, or you must manually set a non-null password.

GUI
1) Enter the Stash website: http://host:7990/admin/users
2) On the left-hand side, click Users.
3) Click Create User.

CLI
Project permissions are: PROJECT_READ, PROJECT_WRITE, or PROJECT_ADMIN
The stash-server is the URL, as in "http://ip-address:7990".
	# Create the user.
	stash --action addUser --server stash-server --user admin --password admin-password --userId user --userFullName "fullname" --userEmail email --userPassword password

	# Add the user to a project.	
	stash --action grantProjectPermissions --server stash-server --user admin --password admin-password --project project --permission permission --userId user

	# Or, add the user to a group that already access to a project/repository.
	stash --action addUserToGroup --server stash-server --user admin --password admin-password --userId user --group group
Table of Contents



Create a Stash group.
Updated: 09/10/14
Version: 3.9.0

GUI
1) Enter the Stash website: http://host:7990/admin/users
2) Click on Administration (little gear in upper-right of page).
3) Click Groups.

CLI
Unknown if it's possible, yet.

Table of Contents





Add a group to a repository.
Updated: 09/11/14
Version: 3.9.0

This assumes the group already exists.

GUI
1) Enter the Stash website: http://host:7990/admin/users
2) Select the project.
3) Select the repository.
4) Click on Settings (little gear in lower-left of page or menu option at the top).
5) Under Permissions, click Repository.

CLI
Unknown if it's possible ... yet.

Table of Contents





Reset a user's password.
Updated: 09/18/14
Version: 3.9.0

A user's initial password is null. However, once a password has been set, it cannot be reset back to null.

Web
1) Log into the Stash page.
2) Click on the gear (Administration) in the upper-right.
3) Under Accounts, click on Users.
4) Click on the user.
5) Select Change Password.

CLI
It isn't possible, that I know of. Even if you use the stash "updateUser" action with the --userPassword parameter, the password doesn't get reset.

Table of Contents





Remove a group from a project.
Updated: 09/18/14
Version: 3.9.0

Web
1) Log into the Stash page.
2) Click on the Project.
3) Click on Settings.
4) Click on Permissions.
5) Hover your mouse over the group entry and a little x will appear on the right side. Click that x.

CLI
Unknown if it's possible ... yet.

Table of Contents


ejostrander@cox.net
Return to the home page .

This page last modified: 03/02/2016