Basic Git Commands - Atlassian Documentation

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Basic Git commands - Atlassian Documentation https://conuence.atlassian.com/bitbucketserver/...

Bitbucket Server latest (4.8) / Git resources

Select another version

Bitbucket Server was previously known as Atlassian Stash. Learn more.

Basic Git commands


Here is a list of some basic Git commands to get you going with Git.

For more detail, check out the Atlassian Git Tutorials for a visual introduction to Git commands and
workflows, including examples.

Git task Notes Git commands

Tell Git Configure the author git config --global user.name "Sam Smith"
who you name and email
git config--globaluser.email
are address to be used
[email protected]
with your commits.

Note that Git strips


some characters (for
example trailing
periods) from
user.name.

Create a git init


new local
repository

Check out Create a working git clone /path/to/repository


a copy of a local
repository repository:

For a remote server, git clone username@host:/path/to/repository


use:

Add files Add one or more git add <filename>


files to staging
(index): git add *

Commit Commit changes to git commit -m "Commit message"


head (but not yet to

1 of 4 08/07/2016 09:40 AM
Basic Git commands - Atlassian Documentation https://conuence.atlassian.com/bitbucketserver/...

the remote
repository):

Commit any files git commit -a


you've added with
git add, and also
commit any files
you've changed
since then:

Push Send changes to the git push origin master


master branch of
your remote
repository:

Status List the files you've git status


changed and those
you still need to add
or commit:

Connect to If you haven't git remote add origin <server>


a remote connected your local
repository repository to a
remote server, add
the server to be able
to push to it:

List all currently git remote -v


configured remote
repositories:

Branches Create a new branch git checkout -b <branchname>


and switch to it:

Switch from one git checkout <branchname>


branch to another:

List all the branches git branch


in your repo, and
also tell you what
branch you're
currently in:

Delete the feature git branch -d <branchname>


branch:

Push the branch to git push origin <branchname>


your remote
repository, so others
can use it:

2 of 4 08/07/2016 09:40 AM
Basic Git commands - Atlassian Documentation https://conuence.atlassian.com/bitbucketserver/...

Push all branches to git push --all origin


your remote
repository:

Delete a branch on git push origin :<branchname>


your remote
repository:

Update Fetch and merge git pull


from the changes on the
remote remote server to
repository your working
directory:

To merge a different git merge <branchname>


branch into your
active branch:

View all the merge git diff


conflicts:
git diff --base <filename>
View the conflicts
git diff <sourcebranch> <targetbranch>
against the base file:

Preview changes,
before merging:

After you have git add <filename>


manually resolved
any conflicts, you
mark the changed
file:

Tags You can use tagging git tag 1.0.0 <commitID>


to mark a significant
changeset, such as
a release:

CommitId is the git log


leading characters of
the changeset ID, up
to 10, but must be
unique. Get the ID
using:

Push all tags to git push --tags origin


remote repository:

Undo local If you mess up, you git checkout -- <filename>


changes can replace the
changes in your

3 of 4 08/07/2016 09:40 AM
Basic Git commands - Atlassian Documentation https://conuence.atlassian.com/bitbucketserver/...

working tree with the


last content in head:

Changes already
added to the index,
as well as new files,
will be kept.

Instead, to drop all git fetch origin


your local changes
and commits, fetch git reset --hard origin/master
the latest history
from the server and
point your local
master branch at it,
do this:

Search Search the working git grep "foo()"


directory for foo():


Was this helpful? Yes No

Have a question about this article?

Ask our community Ask question

See questions about this article

4 of 4 08/07/2016 09:40 AM

You might also like