Before publishing take care of
- Remove usernames and passwords
- Refactor code
- Test code
- Add README.md file
- Add license
- use .gitignore
All you will ever need to know…
…is available for free in this book hosted on git website.
After you will champion the basics I recommend you download GitKraken – this is the tool that will help you visualize what is going on while you type in commands in console and take apart bigger repositories with multiple branches.
sudo apt-get update sudo apt-get install git
git --version // git version 2.11.0
git help git --help git help command
git config --global user.name "Name" git config --global user.email "email@example.com"
Review the settings
git config --list
Initialize a Git repository
Add a remote repository or add a new one
git remote add origin https://github.com/USERNAME/PROJECTNAME git remote set-url origin https...
Download/fork a repo
git clone https://github.com/USERNAME/REPONAME.git
Current state of the project
Start tracking a file
git add FILENAME
Start tracking everything in the current directory
git add .
Add all txt files to the Stage
git add '*.txt'
Update tracking for files that changed names or were deleted
git add -u
Add all new files and updates tracking of files that changed names or were deleted
git add -A
Remove a file or files from staging area
git reset <filename> git reset HEAD -- .
Put the files from Stage to the Repository
git commit -m "cute octocat"
See commits and past changes – commit hash, author, date, the description
To see more information for each commit, where new files were added or deleted — lists all files
git log --summary
Define location of remote repository
git remote add origin https://github.com/try-git/try_git.git
Push local repository to the GitHub
- Push command tells Git where to put our commits
- The name of our remote is origin and the default local branch name is master.
The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do.
- Response – Branch master set up to track remote branch master from origin
git push -u origin master
Check changes on GitHub repository and pull down any new changes
git pull origin master
To see what is different from our last commit
git diff HEAD
Use diff to see changes within files that have already been staged.
git add octofamily/octodog.txt
Changes on stage
git diff --staged
Remove the file from stage
git reset octofamily/octodog.txt git rm --cached FILE
Files can be changed back to how they were at the last commit
git checkout -- octocat.txt
Create a branch
git branch clean_up
Create a branch and check it out at the same time
git checkout -b branchname
To see all branches
git checkout <branch>
Remove the files from disc and stage the removal of files
git rm '*.txt'
Auto remove of the files with the commit
git commit -am "Delete stuff"
Commit your changes
git commit -m "Remove all cats"
Switch back to the master branch so you can copy (or merge) your changes from the clean_up branch back into the master branch
git checkout master
Merge changes from branch to master branch
git merge clean_up
Delete a branch (it doesn’t allow you to delete something that hasn’t been merged)
git branch -d clean_up
Push everything you have been working on to remote repository
Change the origin URL (used when the github username is changed)
git remote set-url origin <NEW GITHUB URL>