Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The Git presentation
- ## The ideea
- Simulate a simple project migration process
- Start from a simple directory structure:
- $ ls
- /remote /project /local
- Assuming a project with a simple structure
- $ ls project project/code project/settings
- project:
- code/ settings/
- project/code:
- code.txt morecode.txt
- project/settings:
- settings1.txt settings2.txt
- 1. #### initialize the repo (optional if only using github)
- $ cd remote
- $ git init --bare
- Initialized empty Git repository in remote/
- 2. #### clone the repo locally
- $ cd local
- $ git clone ../remote .
- Cloning into '.'...
- warning: You appear to have cloned an empty repository.
- done.
- 3. #### copy the project into the local repo
- After copying the project, run `git status`
- $ git status
- On branch master
- No commits yet
- Untracked files:
- (use "git add <file>..." to include in what will be committed)
- code/
- settings/
- nothing added to commit but untracked files present (use "git add" to track)
- Maybe not everything needs to be versioned. To demonstrate that, ignore the `settings` directory.
- 4. #### ignore the settings
- $ echo settings/ > .gitignore
- $ git status
- On branch master
- No commits yet
- Untracked files:
- (use "git add <file>..." to include in what will be committed)
- .gitignore
- code/
- nothing added to commit but untracked files present (use "git add" to track)
- 5. #### commit .gitignore and code
- $ git add .gitignore
- $ git commit -m "added gitignore"
- [master (root-commit) 8d05149] added gitignore
- 1 file changed, 1 insertion(+)
- create mode 100644 .gitignore
- $ git add code
- $ git commit -m "added the code"
- [master 13608ef] added the code
- 2 files changed, 2 insertions(+)
- create mode 100644 code/code.txt
- create mode 100644 code/morecode.txt
- 5. #### push to remote
- $ git push --set-upstream origin
- Enumerating objects: 6, done.
- Counting objects: 100% (6/6), done.
- Delta compression using up to 4 threads
- Compressing objects: 100% (3/3), done.
- Writing objects: 100% (5/5), 390 bytes | 390.00 KiB/s, done.
- Total 5 (delta 0), reused 0 (delta 0)
- To local/../remote
- 8d05149..13608ef master -> master
- Branch 'master' set up to track remote branch 'master' from 'origin'.
- Let's assume that they will be using branches
- 6. #### create a branch
- $ git log
- commit 13608ef5f5efc7b844e82c46180b2c4c8d1f214b (HEAD -> master, origin/master)
- added the code
- commit 8d051491c0dd5015fe258430c80568e8158f2b52
- added gitignore
- $ git branch first-branch
- $ git checkout first-branch
- Switched to branch 'first-branch'
- $ git log
- commit 13608ef5f5efc7b844e82c46180b2c4c8d1f214b (HEAD -> first-branch, origin/master, master)
- added the code
- commit 8d051491c0dd5015fe258430c80568e8158f2b52
- added gitignore
- 1. #### commit some changes on the branch
- $ echo "some more code" >> code/code.txt
- $ git status
- On branch first-branch
- Changes not staged for commit:
- (use "git add <file>..." to update what will be committed)
- (use "git restore <file>..." to discard changes in working directory)
- modified: code/code.txt
- no changes added to commit (use "git add" and/or "git commit -a")
- $ git add code/code.txt
- $ git status
- On branch first-branch
- Changes to be committed:
- (use "git restore --staged <file>..." to unstage)
- modified: code/code.txt
- $ git commit -m "added more code"
- [first-branch 990d3ba] added more code
- 1 file changed, 1 insertion(+)
- $ git log
- commit 990d3baac163a5742233ce9a2745ca7fa1e517dc (HEAD -> first-branch)
- added more code
- commit 13608ef5f5efc7b844e82c46180b2c4c8d1f214b (origin/master, master)
- added the code
- commit 8d051491c0dd5015fe258430c80568e8158f2b52
- added gitignore
- 9. #### change the commit message
- $ git commit --amend -m "[add] more code"
- [first-branch 0675ff3] [add] more code
- Date: Sun Oct 13 19:10:34 2019 +0300
- 1 file changed, 1 insertion(+)
- $ git log
- commit 0675ff33d03a3f9e662c3fe5ded6e15540802b07 (HEAD -> first-branch)
- [add] more code
- commit 13608ef5f5efc7b844e82c46180b2c4c8d1f214b (origin/master, master)
- added the code
- commit 8d051491c0dd5015fe258430c80568e8158f2b52
- added gitignore
- 10. #### push the branch
- $ git push --all
- Enumerating objects: 7, done.
- Counting objects: 100% (7/7), done.
- Delta compression using up to 4 threads
- Compressing objects: 100% (3/3), done.
- Writing objects: 100% (4/4), 373 bytes | 62.00 KiB/s, done.
- Total 4 (delta 0), reused 0 (delta 0)
- To C:/Users/Ameteo/Desktop/git stuff/local/../remote
- * [new branch] first-branch -> first-branch
- $ git log
- commit 0675ff33d03a3f9e662c3fe5ded6e15540802b07 (HEAD -> first-branch, origin/first-branch)
- [add] more code
- commit 13608ef5f5efc7b844e82c46180b2c4c8d1f214b (origin/master, master)
- added the code
- commit 8d051491c0dd5015fe258430c80568e8158f2b52
- added gitignore
- 11. #### merge the changes to master
- Either create a pull request and merge it on github or merge it locally.
- $ git checkout master
- Switched to branch 'master'
- Your branch is up to date with 'origin/master'.
- $ git merge first-branch
- Updating 13608ef..0675ff3
- Fast-forward
- code/code.txt | 1 +
- 1 file changed, 1 insertion(+)
- $ git log
- commit 0675ff33d03a3f9e662c3fe5ded6e15540802b07 (HEAD -> master, origin/first-branch, first-branch)
- [add] more code
- commit 13608ef5f5efc7b844e82c46180b2c4c8d1f214b (origin/master)
- added the code
- commit 8d051491c0dd5015fe258430c80568e8158f2b52
- added gitignore
- 12. #### pull the changes (if merged from github) / push the changes (if merged locally)
- $ git pull
- Updating 13608ef..0675ff3
- Fast-forward
- code/code.txt | 1 +
- 1 file changed, 1 insertion(+)
- Or
- $ git push --all
- Total 0 (delta 0), reused 0 (delta 0)
- To C:/Users/Ameteo/Desktop/git stuff/local/../remote
- 13608ef..0675ff3 master -> master
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement