Git For Beginners

From UABgrid Documentation
(Difference between revisions)
Jump to: navigation, search
m
m
Line 28: Line 28:
 
git init
 
git init
 
</pre>
 
</pre>
 +
 +
== Review changes ==
 +
Once you have made changes to the files in a git repository, you can review your edits using following commands.
 +
 +
To list all new or modified files to be commited:
 +
<pre>
 +
[ravi89@login001 Tutorial_June_2018]$ git status
 +
# On branch master
 +
#
 +
# Initial commit
 +
#
 +
# Untracked files:
 +
#  (use "git add <file>..." to include in what will be committed)
 +
#
 +
# test
 +
nothing added to commit but untracked files present (use "git add" to track)
 +
[ravi89@login001 Tutorial_June_2018]$
 +
</pre>
 +
 +
To show file differences that have not yet been staged for a commit:
 +
<pre>
 +
[ravi89@login001 Tutorial_June_2018]$ git diff
 +
diff --git a/test b/test
 +
index 19e2dd9..d04e379 100644
 +
--- a/test
 +
+++ b/test
 +
@@ -1 +1,3 @@
 +
Show git status
 +
+
 +
+Demo git diff
 +
[ravi89@login001 Tutorial_June_2018]$ git status
 +
</pre>
 +
 +
To see the file differences for file that have been staged, use: '''git diff --staged'''
 +
 +
== Commit a file ==
 +
To commit a file you first need to add the file where you have made changes, i.e. stage the file:
 +
<pre>
 +
git add CHANGED_FILE
 +
</pre>
 +
This snapshots/stages the file in preparation for versioning.
 +
 +
Next commit these changes  to record file snapshots permanently in version history
 +
<pre>
 +
git commit -m "YOUR_COMMIT_MESSAGE"
 +
</pre>
 +
 +
== Git History ==

Revision as of 16:42, 18 June 2018

Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people.


Contents

Configuration

To configure user information for all local repositories use the following commands:

  • Set the name you want attached to your commit transactions.
 git config --global user.name "[name]"
  • Set the email you want atached to your commit transactions
git config --global user.email "[email address]"

Initializing a git repository

To initialize a new git repository, run:

[ravi89@login001 Tutorial_June_2018]$ git init test
Initialized empty Git repository in /data/user/ravi89/HPC_Training/Tutorial_June_2018/test/.git/
[ravi89@login001 Tutorial_June_2018]$

To make an already existing directory, a git repo, run:

cd EXISTING_DIRECTORY
git init

Review changes

Once you have made changes to the files in a git repository, you can review your edits using following commands.

To list all new or modified files to be commited:

[ravi89@login001 Tutorial_June_2018]$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	test
nothing added to commit but untracked files present (use "git add" to track)
[ravi89@login001 Tutorial_June_2018]$

To show file differences that have not yet been staged for a commit:

[ravi89@login001 Tutorial_June_2018]$ git diff
diff --git a/test b/test
index 19e2dd9..d04e379 100644
--- a/test
+++ b/test
@@ -1 +1,3 @@
 Show git status
+
+Demo git diff
[ravi89@login001 Tutorial_June_2018]$ git status

To see the file differences for file that have been staged, use: git diff --staged

Commit a file

To commit a file you first need to add the file where you have made changes, i.e. stage the file:

git add CHANGED_FILE

This snapshots/stages the file in preparation for versioning.

Next commit these changes to record file snapshots permanently in version history

git commit -m "YOUR_COMMIT_MESSAGE"

Git History

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox