Alex Pacheco
LTS Research Computing
install via package manager
sudo apt-get install git-all
sudo yum install git-all
sudo zypper install git
Mac OSX: Visit https://git-scm.com/download/mac
Windows: Visit https://git-scm.com/download/win
MobaXterm
Alternative:
apt-cyg install git
There are GUI tools available that are not covered in this tutorial. Please do not ask me questions about using these tools, I have no clue how to use them nor do I plan on learning how to use them.
git config --global user.name "Enter your name"
git config --global user.email "Enter your email address"
git config --global core.editor emacs
git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -nosession"
apt-cyg install emacs
git config --list
## user.name=Alex Pacheco
## user.email=abpacheco@gmail.com
## push.default=simple
## alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
## alias.pub=push webapps +gh-pages:refs/heads/master
## core.repositoryformatversion=0
## core.filemode=true
## core.bare=false
## core.logallrefupdates=true
## core.ignorecase=true
## core.precomposeunicode=true
git init git-train
## Initialized empty Git repository in /Users/apacheco/Tutorials/DCVS/bitbucket/git-train/.git/
touch README
git add README
git commit -m "My First commit"
## [master (root-commit) a8e897e] My First commit
## 1 file changed, 1 insertion(+)
## create mode 100644 README
git init --bare git_train.git
git clone file://{path to bare repo}/git_train.git
git status
## On branch master
## nothing to commit, working directory clean
cat << EOF > README
## Description
My first git repository
## Project
Building a webpage
EOF
cat << EOF > index.html
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>My First Webpage</title>
</head>
<body>
<article>
<h2>Under Contruction</h2>
<p>No soup for you. Come back one year!</p>
</article>
</body>
</html>
EOF
git status
## On branch master
## Changes not staged for commit:
## (use "git add <file>..." to update what will be committed)
## (use "git checkout -- <file>..." to discard changes in working directory)
##
## modified: README
##
## Untracked files:
## (use "git add <file>..." to include in what will be committed)
##
## index.html
##
## no changes added to commit (use "git add" and/or "git commit -a")
git add README
## On branch master
## Changes to be committed:
## (use "git reset HEAD <file>..." to unstage)
##
## modified: README
##
## Untracked files:
## (use "git add <file>..." to include in what will be committed)
##
## index.html
git add index.html
## On branch master
## Changes to be committed:
## (use "git reset HEAD <file>..." to unstage)
##
## modified: README
## new file: index.html
git status -s
## M README
## A index.html
git commit -m "Created index.html, modified README with useful information"
## [master 5dccf54] Created index.html, modified README with useful information
## 2 files changed, 18 insertions(+)
## create mode 100644 index.html
git commit
git status
## On branch master
## nothing to commit, working directory clean
-a
flag to git commit
commandgit commit -a -m
# OR
git commit -am
git log
## commit 5dccf54e60fe54278e1ce02a34f4e15e0e21eda5
## Author: Alex Pacheco <abpacheco@gmail.com>
## Date: Mon Oct 31 20:21:01 2016 -0400
##
## Created index.html, modified README with useful information
##
## commit a8e897e45466f1f713d528aa6d246c5af633b6f0
## Author: Alex Pacheco <abpacheco@gmail.com>
## Date: Mon Oct 31 20:21:01 2016 -0400
##
## My First commit
git log --pretty=oneline
git log --pretty=format:"%h - %an, %ar : %s"
## 5dccf54e60fe54278e1ce02a34f4e15e0e21eda5 Created index.html, modified README with useful information
## a8e897e45466f1f713d528aa6d246c5af633b6f0 My First commit
##
## 5dccf54 - Alex Pacheco, 1 second ago : Created index.html, modified README with useful information
## a8e897e - Alex Pacheco, 1 second ago : My First commit
git log
rm Project.md
git status
git rm Project.md
## On branch master
## Changes not staged for commit:
## (use "git add/rm <file>..." to update what will be committed)
## (use "git checkout -- <file>..." to discard changes in working directory)
##
## deleted: Project.md
##
## no changes added to commit (use "git add" and/or "git commit -a")
## rm 'Project.md'
--cached
option to git rm
git rm --cached About.md
## rm 'About.md'
## On branch master
## Changes to be committed:
## (use "git reset HEAD <file>..." to unstage)
##
## deleted: About.md
## deleted: Project.md
##
## Untracked files:
## (use "git add <file>..." to include in what will be committed)
##
## About.md
echo About.md > .gitignore
## On branch master
## Changes to be committed:
## (use "git reset HEAD <file>..." to unstage)
##
## deleted: About.md
## deleted: Project.md
##
## Untracked files:
## (use "git add <file>..." to include in what will be committed)
##
## .gitignore
git mv
commandgit mv README README.md
## On branch master
## Changes to be committed:
## (use "git reset HEAD <file>..." to unstage)
##
## deleted: About.md
## deleted: Project.md
## renamed: README -> README.md
##
## Untracked files:
## (use "git add <file>..." to include in what will be committed)
##
## .gitignore
--amend
option to git commit
takes your staging area and uses it for commitgit commit -m 'Deleted Project.md, Renamed README and untracked About.md'
git add .gitignore
git commit --amend -m 'Deleted Project.md, renamed README, untracked About.md and added .gitignore'
## [master 485d6ad] Deleted Project.md, Renamed README and untracked About.md
## 3 files changed, 0 insertions(+), 0 deletions(-)
## delete mode 100644 About.md
## delete mode 100644 Project.md
## rename README => README.md (100%)
##
##
## [master b33a696] Deleted Project.md, renamed README, untracked About.md and added .gitignore
## 4 files changed, 1 insertion(+)
## create mode 100644 .gitignore
## delete mode 100644 About.md
## delete mode 100644 Project.md
## rename README => README.md (100%)
Library & Technology Services provide a Git hosted services that is accessible within Lehigh only
Creating a repository on a hosted service i.e. remote repository
Pushing your local git repo to the remote repository
How to check remote repositories
git remote -v
how to add remote repository
git remote add <shortname> <url>
What if you want to collaborate with someone and want to take a copy of their repository
git clone https://gogs.cc.lehigh.edu/alp514/git-train.git
Push changes in local repo to remote
git push <name> <branch>
Update changes from remote to your local repo
git fetch
git merge HEAD
Alternatively, run git pull
which will do the above two commands
Adding another remote
git remote add github https://github.com/alexpacheco/git-train.git
Listing your remotes
git remote -v
Renaming a remote
git remote rename github backup
deleting a remote
git remote rm backup
git tag -a v1.4 -m "my version 1.4"
git tag -a v1.2 9fceb02
git tag
git push origin [tagname]
git push origin --tags
git checkout -b [branchname] [tagname]
Branching means you diverge from the main line of development and continue to do work without messing with that main line
Create a new branch
git branch testing
git checkout testing
git checkout master
git merge testing
and
git branch -d testing