
Github and Git helps emenscily with web development it is a revision editor change this and make longer
What is Git
Git is a distributed version control system that tracks versions of files. It is often used to control source code by programmers who are developing software collaboratively. Git maintains a local copy of a repository, a.k.a. repo, with history and version-tracking abilities, independent of network access or a central server. A repo is stored on each computer in a standard directory with additional, hidden files to provide version control capabilities.
What is Github
GitHub is a cloud-based platform that allows developers to store, share, and collaborate on code. It uses Git software, providing the distributed version control of Git plus access control, bug tracking, software feature requests, task management, continuous integration, and wikis for every project. It is commonly used to host open source software development projects.
Configurations
First set some configuration settings to work with Git. If you’ve signed up to Github use those settings so that they can interact with each other.
git config --global user.name "Your Username"
The username you use on Github
git config --global user.email "Your email"
The email you use on Github
git config --global color.ui true
highlights the git code for easier reading
git config --list
Lists your git config settings global - default settings used in all git repros
.DS_Store files
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
Finds and removes .DS_Store files from your project and Git. Do this from the root of your project
Add - **/.DS_Store
to the .gitignore
file
Starting a Repository
A Git repository is just a folder that holds your project. It can be empty or already contain project files and folders. Git places a hidden folder at the root of the project folder/repository where it tracks the projects files and watches for changes.
git init
initialize a repository
git status
Shows the status of the repository
Staging Files
The command git status
shows any changes to the projects files. Before Git commits the files it needs to add them to the staging area. Git manipulates the staging area with the following commands.
git add <file-name>
Add file to commit stage
git add <file-name> <another-file-name> <and-another-file-name>
Add multiple files to commit stage
git add .
Add all files in the root directory - note the period
git add --all
Add all files in the project
git add -A
Add all files in the project
git rm --cached <file-name>
Remove file from commit list
git reset <file-name>
Remove file from commit list
Committing to a Repository
After adding files to the staging area Git will commit the changes or new files to the current branch.
git commit -m "your message"
Commit with message
git reset --soft HEAD^
Undo the last commit
git commit --amend -m "enter your message"
Use instead of git reset
to amend the last commit and rewriting the message
eg. git add I-forgot-this-file
git commit --amend -m "added I-forgot-this-file"
Pulling and Pushing From and To Repositories
Working between the local and remote repositories (Github)
git remote add origin <repo link>
Set up the origin path to your on-line repository
git push -u origin master
upload to the on-line repository master branch
git push
because we ran git push -u origin master
we can now just use git push
git clone <clone link>
Download a on-line project to a folder on your computer
git clone <clone link> new-name
Download and change the name if you wish
git pull
Update the local repository with any changes made in the remote repository
Branching
The main branch in a repository is the master branch
. If we need to add new features to the project we can make them on separate branches so as not to upset the master branch
. This allows multi developers to work on different features at the same time. When the features are finished and passed the branches can be merged with the master branch
.
git branch
Lists all the repository branches
git branch <branch-name>
Create a new branch
git checkout <branch-name>
Switch to branch
git merge <branch-name>
Merge the branch into master branch Switch to the master branch
before merging
git branch -d <branch-name>
delete branch
git checkout -b <branch-name>
Create and switch to new branch