Running these commands will setup your global git settings. You should obviously use your own contact details. Should you wish to change your details, you can edit the '~/.gitconfig' file for global settings, or edit '.git/config' to change settings on a particular repo.

+

Running these commands will setup your global git settings. You should obviously use your own contact details.

−

<code>git config --global user.name "John Q. Public"</code>

+

git config --global user.name "John Q. Public"

+

git config --global user.email "john.public@example.com"

+

git config --global color.ui auto

−

<code>git config --global user.email "john.public@example.com"</code>

+

Should you wish to change your details later on, you can manually edit the <code>~/.gitconfig</code> file for global settings, or edit <code>.git/config</code> to change settings on a particular repo. Alternatively, you can simply run the above commands again with new details.

−

+

−

<code>git config --global color.ui auto</code>

+

See the [http://www.kernel.org/pub/software/scm/git/docs/git-config.html <code>git config</code>] documentation for many more configuration options.

See the [http://www.kernel.org/pub/software/scm/git/docs/git-config.html <code>git config</code>] documentation for many more configuration options.

Line 21:

Line 21:

<pre>[user@host directory-name (master)]$ </pre>

<pre>[user@host directory-name (master)]$ </pre>

−

To enable this, you can take advantage of the <code>__git_ps1</code> function, provided by <code>/etc/bash_completion.d/git</code> in the git package. Add this line to <code>~/.bashrc</code>:

+

To enable this, you can take advantage of the <code>__git_ps1</code> function, provided by <code>/usr/share/git-core/contrib/completion/git-prompt.sh</code> in the git package. Add those lines to <code>~/.bashrc</code>:

If you do not have the [https://admin.fedoraproject.org/pkgdb/acls/name/bash-completion bash-completion] package installed, you must manually source the git completion script prior to using <code>__git_ps1()</code>. To do this, add to <code>~/.bashrc</code>, either:

If you do not have the [https://admin.fedoraproject.org/pkgdb/acls/name/bash-completion bash-completion] package installed, you must manually source the git completion script prior to using <code>__git_ps1()</code>. To do this, add "<code>source /etc/bash_completion.d/git</code>" to <code>~/.bashrc</code>.

You might also want to display when there are changes in your work tree or the git index:

You might also want to display when there are changes in your work tree or the git index:

−

+

[user@host directory-name (master*)]$

−

<pre>[user@host directory-name (master*)]$

+

[user@host directory-name (master+)]$

−

[user@host directory-name (master+)]$

+

[user@host directory-name (master%)]$

−

[user@host directory-name (master%)]$ </pre>

+

* On the first line, a tracked file was modified

* On the first line, a tracked file was modified

Line 44:

Line 44:

To do so, simply add these lines in your <code>~/.bashrc</code>, right before the line modifying your prompt:

To do so, simply add these lines in your <code>~/.bashrc</code>, right before the line modifying your prompt:

−

+

export GIT_PS1_SHOWDIRTYSTATE=true

−

<pre>export GIT_PS1_SHOWDIRTYSTATE=true

+

export GIT_PS1_SHOWUNTRACKEDFILES=true

−

export GIT_PS1_SHOWUNTRACKEDFILES=true</pre>

+

See the comments at the beginning of <code>/etc/bash_completion.d/git</code> for more details.

See the comments at the beginning of <code>/etc/bash_completion.d/git</code> for more details.

Line 89:

Line 88:

Use:

Use:

−

<code>git branch -a</code>

+

<code>git branch -r</code>

−

to determine the name of the remote branch you want to work on. Remote branches will be preceded by <code>origin/</code>. Then use this to switch to it:

+

to determine the name of the upstream branch you want to work on. Then use this to switch to it:

−

<code>git checkout --track -b <branch> origin/<branch></code>

+

<code>git checkout --track origin/<branch></code>

+

+

This creates a local branch named <code><branch></code> and tells git that it came from <code>origin/<branch></code>. Using <code>git status</code> will show you whether your local branch is ahead, behind, or otherwise different than the upstream branch.

+

+

If you want to use a different name for your local branch, you can use:

Should you wish to change your details later on, you can manually edit the ~/.gitconfig file for global settings, or edit .git/config to change settings on a particular repo. Alternatively, you can simply run the above commands again with new details.

Display current branch in bash

If you work with branches, and you should, this setting helps you keep track of which branch you are in at a given time. If you are in a git working directory, it shows the current branch as part of the prompt:

[user@host directory-name (master)]$

To enable this, you can take advantage of the __git_ps1 function, provided by /usr/share/git-core/contrib/completion/git-prompt.sh in the git package. Add those lines to ~/.bashrc:

See the comments at the beginning of /etc/bash_completion.d/git for more details.

Initialize a new repo

mkdir repo && cd repo && git init

Once you've created a repo, you'll find a '.git' folder inside it. What you essentially have at this point is a bare repo -- a repository with the git configs, but no actual files contained in the repository. Now let's create a file and tell git that we want it to be part of our repo. From the repo directory (not the .git directory), type:

echo "Blah" > test.txt

git add test.txt

We can then commit the changes by typing:

git commit test.txt

Another way of committing all the changes (without having to specify all the files that have changed) is to type:

git commit -a

Either way, it will bring up whichever editor you have defined in $EDITOR and allow you to write a commit log message explaining the changes you've made. A commit log message usually consists of:

a one-line summary of your changes

a blank line

one or more additional lines with more detail. These lines are optional.

You can always check the status of your current repo by typing

git status

Developer Operations

Create a new local branch

git checkout -b <branch>

Push and create a new remote branch from an existing local branch of the same name

git push origin <branch>

Switch to a branch that was pushed remotely

Use:

git branch -r

to determine the name of the upstream branch you want to work on. Then use this to switch to it:

git checkout --track origin/<branch>

This creates a local branch named <branch> and tells git that it came from origin/<branch>. Using git status will show you whether your local branch is ahead, behind, or otherwise different than the upstream branch.

If you want to use a different name for your local branch, you can use:

git checkout --track --branch <some-other-name> origin/<branch>

Maintainer Operations

Remove a remote branch

This is a dangerous operation. If there's any chance that other people are using the remote branch, you should at least warn them before doing this.

This doesn't entirely work right now for Fedora pkgs git This may give a (hook denied) error. See [1] for details.

Assuming you had a branch named blah on the remote server, you could remove it by typing: