git
was created by Linus Torvalds, the creator of Linux- In short,
git
manages changes in files and is one of the leading tools for source control. - Some basic terminology
commit
defines the state of files as they were at that point in timecommit
s are affiliated with repositories and branches- A current
commit
is called ahead
$ sudo yum install -y git
$ sudo apt-get install -y git
- Homebrew:
$ brew install git
If you do not have homebrew installed, run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Download git
- Use Chocolatey
$ mkdir [repo-name]
$ cd [repo-name]
$ git init
initialize repository
init
will create a .git directory in the repository
OUTPUT: Initialized empty Git repository in /Users/name/path/to/folder/.git/
- Set global username
git config --global user.name [username]
- Set global email
git config --global user.email [email_addr]
- Check status:
$ git status
- Adding files:
$ git add -A
flag will add all pending files - Add one file:
$ git add [file name]
- Commit files:
$ git commit -m "message"
- Stop tracking a file:
$ git rm [file]
- Push to master:
$ git push origin master
- Set origin:
$ git remote add origin https://github.com/user/repo.git
- Set upstream:
$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
- Clone repo locally:
$ git clone [path-to-github-repo.git]
- Create a branch:
$ git branch [branch-name]
- Start working in a branch:
$ git checkout [branch-name]
Do both:
$ git checkout -b [branch-name]
NOTE:q
to quit view
- Check file difference:
$ git diff
- Check log:
$ git log
- Merge a branch:
$ git merge [branch-name]
- Push to master:
$ git push origin master
- you changed and/or added files in a repo and you want these files to be grouped into a branch prior to merging with master
- checkout a branch:
$ git checkout -b [branch-name]
- check status:
$ git status
- check diff:
$ git diff
- add files:
$ git add -A
- commit changes:
$ git commit -m "message"
- checkout master:
$ git checkout master
- merge changes:
$ git merge [branch-name]
- push to github/lab:
$git push origin master