Skip to content

Jeromexsu/tutorial-git

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 

Repository files navigation

https://git-scm.com/docs/gittutorial

initialize a new project

git init

git add - add new files, stage changes, explained

git add <file> [files]

you can use . to add all files in the working directory

git add is used both for new and newly modified files, and in both cases it takes a snapshot of the given files and stages that content in the index, ready for inclusion in the next commit.

making changes

Modify some files, then add their updated contents to the index use git add. You can see what is about to be committed using git diff with the --cached option.

git diff --cached

(Without --cached, git diff will show you any changes that you’ve made but not yet added to the index.)

view project history

git log

use -p to see complete diffs at each step use --stat --summary to get a nice summary

branch

use git branch to create a new branch. We will create a new branch called beta in this project and modify this file on each branch.

to create a branch git branch <branch_name> to switch to another branch git switch <branch_name>

[beta] now we are in a new branch, all the modification we made in main branch has disappeared. I will write something in this section, commit it and see what will happen.

[main] I just switch to beta branch, add some text, commit and switch back. As we can see, all modifications I made under beta branch are invisible under main branch.

Use git merge to merge two branches. All conflicts will left in the file with marks. You should resolve them mannually.

Use `git branch -d <branch_name> to delete branch.

Collaboration

[changes below are made on another end] We use git clone, git pull for collaboration. Use git clone to clone another project manage by git. Make and commit changes on local project. Tell the remote end to merge changes by `git pull <remote_add> <branch_name>.

git fetch can pull changes made by remote end without merge it. Changes will be stored in another branch. If you really want to merge from remote end, use git merge. Use git log -p HEAD..FETCH_HEAD to see what changes has been made since it has been forked on the remote end. Use git log -p HEAD...FETCH_HEAD to see what changes has been made on both ends.

git clone will implicitly add the source as remote repository for the working directory. You can mannually add remote repo by git remote add. To see remote repo, use git config --get remote.origin.url

Git also keeps a pristine copy of remote end's branch under the name 'origin/'. To see it, use git branch -r.

Exploriing history

Git history is represented as a series of interrelated commits. Use git log to list commits.

It will look like this

commit 367f29da0dbe8879c14427154fc463cf0ed913fc (HEAD -> main)
Author: Jerome Su <[email protected]>
Date:   Fri Aug 18 12:11:43 2023 +0800

    Tutorial - Add Content
    git fetch
    git log -p HEAD...FETCH_HEAD
    git log -p HEAD..FETCH_HEAD
    git merge

367f29... is the name that generated by git for this commit.

Use git show <commit> to check out the detail about this commit. You can use any initial part of the name that is long enough to uniquely identify the commit.

You can also give commits the names of your own, using git tag <name> <commit>.

Working with github

The repo on github is basically a remote end of our local repo. After initialize the repo and get the web address, use git remote add origin <addr> to link both ends. The set the upstream of the branch, using git branch --set-upstream-to=origin/<branch_remote> <branch_local> to set the upstream branch. Then git push

About

Tutorial repo for git

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published