git clone, git config, git add, git status, git commit, git push, git pull, git branch, git checkout, and git merge
git clone https://project.git
git clone ssh://project.git
git clone https://project.git --branch main-release --single-branch
git fetch && git checkout main-release From https://project.git
git pull --all
git fetch, git merge and git mergetool (manually)
git status
git add -a
git add file
git commit -m 'initial commit'
push to original master
git push origin master
git checkout future-plans
to merge back -- fast forward
git checkout master
git merge future-plans
to delete the future plans
git branch -d future-plans
pull main
git checkout main-release
git pull
git checkout NAME
git checkout bugfix/SD-2979-jsissues
git status
git status -uno
git fetch origin
git fetch
git log HEAD.. --oneline
git add -a
git commit -m "...."
git push origin NAME
git push origin bugfix/SD-2979-jsissues
git remote update to bring your remote refs up to date. Then you can do one of several things, such as:
$ cd /c/user/my_project
$ git init
to track initial files
$ git add *.c
$ git add LICENSE
$ git commit -m 'initial project version'
Cloning an Existing Repository
$ git clone https://github.com/libgit2/libgit2
or if you want the dir name to be different
$ git clone https://github.com/libgit2/libgit2 mylibgit
Make changes ==> Stage (add) ==> commit ==> push
checking the status of the files
$ git status
$ git status -s or
$ git status --short
$ git diff (showes exact lines), changes not yet staged
$ git diff --staged (changes staged but not committed)
Create a new file like ReadMe.txt
$ git add ReadMe.txt or $ git add --all
$ git commit -m "ReadMe.txt"
Stage and commit at the same time
$ git commit -a -m 'added new benchmarks'
Removing Files use -f flag if the file has already been staged
$ git rm PROJECTS.md
Remove from staging area but not from the project
$ git rm --cached README
Viewing the Commit History
$ git log
$ git log -p -2 (patch)
$ git log --stat
$ git log --pretty=oneline
$ git log --pretty=format:"%h - %an, %ar : %s"
$ git log --since=2.weeks
$ git log --pretty="%h - %s" --author='Junio C Hamano' --since="2008-10-01" \ --before="2008-11-01" --no-merges -- t/
$ git log --oneline --decorate
$ git log -5 --oneline --decorate
$ git log --oneline --decorate --graph --all
$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend
2. Unstaging a Staged File, lets say added README.md and CONTRIBUTING.md and want to unstage CONTRIBUTING.md
$ git status (will give you the current status and infact if you look closely will give the command to unstage as well)
$ git reset HEAD CONTRIBUTING.md
3. Unmodifying a Modified File, read git status closely. Any changes you made to that file are gone — Git just copied another file over it.
$ git checkout -- CONTRIBUTING.md
$ git branch -v
$ git branch testing (create)
$ git checkout testing
$ git checkout -b testing (create a switchto)
$ git checkout -b sf testing (create with name sf from testing)
$ git branch -u testing (set local branch to track testing)
$ git branch -vv (to look at the tracking branches)
Merge testing with master
$ git checkout master
$ git merge testing
if merge issues then
$ git mergetool
Delete branch
$ git branch -d testing
$ git branch -D testing (forcefully)
$ git branch --merged (To see which branches are already merged into the branch you’re on)
$ git branch --no-merged (work that isn’t merged in yet)
$ git branch --no-merged master (state with respect to a specific branch)
$ git ls-remote
*.a
# but do track lib.a, even though you're ignoring .a files above
!lib.a
# only ignore the TODO file in the current directory, not subdir/TODO
/TODO
# ignore all files in any directory named build
build/
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt
# ignore all .pdf files in the doc/ directory and any of its subdirectories
doc/**/*.pdf
https://www.youtube.com/watch?v=N1KNw1tr47k
TortoiseGit Tutorial 2: How to clone Git Repository
https://www.youtube.com/watch?v=51A3K8up51E
TortoiseGit Tutorial 3: git add (staging) , commit and push
https://www.youtube.com/watch?v=ntx5n_KTk1Y
TortoiseGit Tutorial 4: git fetch, merge and pull
https://www.youtube.com/watch?v=SCqfRRyJfc4
TortoiseGit Tutorial 5: Git branching (How to create branch in GitHub, fetch it and push changes)
https://www.youtube.com/watch?v=lXtIvckcYhk
TortoiseGit Tutorial 6: Merging branches (git merge) - Fast Forward vs 3-way merge
https://www.youtube.com/watch?v=AMzIPsp5dGg
TortoiseGit Tutorial 7: Create, switch or delete branch using tortoiseGit
https://www.youtube.com/watch?v=zbc1gIMm4gs
TortoiseGit Tutorial 8: Stashing (save local changes) using tortoiseGit
https://www.youtube.com/watch?v=MHfp1lM6fT8
TortoiseGit Tutorial 9(b): Undoing local changes using tortoiseGit reset option (hard)
https://www.youtube.com/watch?v=zRjQ500p70U
TortoiseGit Tutorial 9(c): git clean using tortoiseGit (hard and clean, do clean with dry run)
https://www.youtube.com/watch?v=mBu1P4fsDBA
TortoiseGit Tutorial 9(d): git revert using tortoiseGit (undo published commits)
https://www.youtube.com/watch?v=U391TdnEOp0
TortoiseGit Tutorial 10: Create and apply patch using tortoiseGit
https://www.youtube.com/watch?v=a8O9DUx7A0E
TortoiseGit Tutorial 11: DiffMerge Tool integration in tortoiseGit
https://www.youtube.com/watch?v=eIymvIcUmgo
TortoiseGit Tutorial 12: How to use cherry pick in git ?
https://www.youtube.com/watch?v=hJmIkYjv9Nc
Tutorials
Basics
git clone ....git clone https://project.git
git clone ssh://project.git
git clone https://project.git --branch main-release --single-branch
git fetch && git checkout main-release From https://project.git
git pull --all
git fetch, git merge and git mergetool (manually)
git status
git add -a
git add file
git commit -m 'initial commit'
push to original master
git push origin master
git checkout future-plans
to merge back -- fast forward
git checkout master
git merge future-plans
to delete the future plans
git branch -d future-plans
pull main
git checkout main-release
git pull
git checkout NAME
git checkout bugfix/SD-2979-jsissues
git status
git status -uno
git fetch origin
git fetch
git log HEAD.. --oneline
git add -a
git commit -m "...."
git push origin NAME
git push origin bugfix/SD-2979-jsissues
git remote update to bring your remote refs up to date. Then you can do one of several things, such as:
- git status -uno will tell you whether the branch you are tracking is ahead, behind or has diverged. If it says nothing, the local and remote are the same.
- git show-branch *master will show you the commits in all of the branches whose names end in master (eg master and origin/master).
- If you use -v with git remote update you can see which branches got updated, so you don't really need any further commands.
Advance
to create a git repository locally$ cd /c/user/my_project
$ git init
to track initial files
$ git add *.c
$ git add LICENSE
$ git commit -m 'initial project version'
Cloning an Existing Repository
$ git clone https://github.com/libgit2/libgit2
or if you want the dir name to be different
$ git clone https://github.com/libgit2/libgit2 mylibgit
Make changes ==> Stage (add) ==> commit ==> push
checking the status of the files
$ git status
$ git status -s or
$ git status --short
$ git diff (showes exact lines), changes not yet staged
$ git diff --staged (changes staged but not committed)
Create a new file like ReadMe.txt
$ git add ReadMe.txt or $ git add --all
$ git commit -m "ReadMe.txt"
Stage and commit at the same time
$ git commit -a -m 'added new benchmarks'
Removing Files use -f flag if the file has already been staged
$ git rm PROJECTS.md
Remove from staging area but not from the project
$ git rm --cached README
Viewing the Commit History
$ git log
$ git log -p -2 (patch)
$ git log --stat
$ git log --pretty=oneline
$ git log --pretty=format:"%h - %an, %ar : %s"
$ git log --since=2.weeks
$ git log --pretty="%h - %s" --author='Junio C Hamano' --since="2008-10-01" \ --before="2008-11-01" --no-merges -- t/
$ git log --oneline --decorate
$ git log -5 --oneline --decorate
$ git log --oneline --decorate --graph --all
Undoing things
1. the second commit replaces the results of the first
$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend
2. Unstaging a Staged File, lets say added README.md and CONTRIBUTING.md and want to unstage CONTRIBUTING.md
$ git status (will give you the current status and infact if you look closely will give the command to unstage as well)
$ git reset HEAD CONTRIBUTING.md
3. Unmodifying a Modified File, read git status closely. Any changes you made to that file are gone — Git just copied another file over it.
$ git checkout -- CONTRIBUTING.md
Working with remotes
$ git remote
$ git remote -v (shows you the URLs that Git has stored for the shortname to be used when reading and writing to that remote)
1. adding remote repository
git remote add :
$ git remote add pb https://github.com/paulboone/ticgit
Now you can use the string pb
$ git fetch pb
2. Fetching and Pulling from Your Remotes
$ git fetch
3. Inspecting a Remote
$ git remote show origin
4. Renaming and Removing Remotes
$ git remote rename pb paul
$ git remote remove paul
$ git remote -v (shows you the URLs that Git has stored for the shortname to be used when reading and writing to that remote)
1. adding remote repository
git remote add
$ git remote add pb https://github.com/paulboone/ticgit
Now you can use the string pb
$ git fetch pb
2. Fetching and Pulling from Your Remotes
$ git fetch
3. Inspecting a Remote
$ git remote show origin
4. Renaming and Removing Remotes
$ git remote rename pb paul
$ git remote remove paul
Branches -- A branch in Git is simply a lightweight movable pointer to one of the commits
$ git branch
$ git branch -v
$ git branch testing (create)
$ git checkout testing
$ git checkout -b testing (create a switchto)
$ git checkout -b sf testing (create with name sf from testing)
$ git branch -u testing (set local branch to track testing)
$ git branch -vv (to look at the tracking branches)
Merge testing with master
$ git checkout master
$ git merge testing
if merge issues then
$ git mergetool
Delete branch
$ git branch -d testing
$ git branch -D testing (forcefully)
$ git branch --merged (To see which branches are already merged into the branch you’re on)
$ git branch --no-merged (work that isn’t merged in yet)
$ git branch --no-merged master (state with respect to a specific branch)
$ git ls-remote
Creating an ignore file .gitignore, check https://github.com/github/gitignore for more details.
# ignore all .a files*.a
# but do track lib.a, even though you're ignoring .a files above
!lib.a
# only ignore the TODO file in the current directory, not subdir/TODO
/TODO
# ignore all files in any directory named build
build/
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt
# ignore all .pdf files in the doc/ directory and any of its subdirectories
doc/**/*.pdf
TortoiseGit (Nice and Simple -- External)
TortoiseGit Tutorial 1: How git workshttps://www.youtube.com/watch?v=N1KNw1tr47k
TortoiseGit Tutorial 2: How to clone Git Repository
https://www.youtube.com/watch?v=51A3K8up51E
TortoiseGit Tutorial 3: git add (staging) , commit and push
https://www.youtube.com/watch?v=ntx5n_KTk1Y
TortoiseGit Tutorial 4: git fetch, merge and pull
https://www.youtube.com/watch?v=SCqfRRyJfc4
TortoiseGit Tutorial 5: Git branching (How to create branch in GitHub, fetch it and push changes)
https://www.youtube.com/watch?v=lXtIvckcYhk
TortoiseGit Tutorial 6: Merging branches (git merge) - Fast Forward vs 3-way merge
https://www.youtube.com/watch?v=AMzIPsp5dGg
TortoiseGit Tutorial 7: Create, switch or delete branch using tortoiseGit
https://www.youtube.com/watch?v=zbc1gIMm4gs
TortoiseGit Tutorial 8: Stashing (save local changes) using tortoiseGit
https://www.youtube.com/watch?v=MHfp1lM6fT8
TortoiseGit Tutorial 9(b): Undoing local changes using tortoiseGit reset option (hard)
https://www.youtube.com/watch?v=zRjQ500p70U
TortoiseGit Tutorial 9(c): git clean using tortoiseGit (hard and clean, do clean with dry run)
https://www.youtube.com/watch?v=mBu1P4fsDBA
TortoiseGit Tutorial 9(d): git revert using tortoiseGit (undo published commits)
https://www.youtube.com/watch?v=U391TdnEOp0
TortoiseGit Tutorial 10: Create and apply patch using tortoiseGit
https://www.youtube.com/watch?v=a8O9DUx7A0E
TortoiseGit Tutorial 11: DiffMerge Tool integration in tortoiseGit
https://www.youtube.com/watch?v=eIymvIcUmgo
TortoiseGit Tutorial 12: How to use cherry pick in git ?
https://www.youtube.com/watch?v=hJmIkYjv9Nc
Tutorials
- https://dont-be-afraid-to-commit.readthedocs.io/en/latest/git/commandlinegit.html
- https://github.com/GarageGames/Torque2D/wiki/Cloning-the-repo-and-working-with-Git
- https://guides.github.com/activities/forking/
- https://help.github.com/en/articles/adding-an-existing-project-to-github-using-the-command-line