-
Notifications
You must be signed in to change notification settings - Fork 3
2.3 Using Git
Making changes to the repository is one thing but the other is to share your changes with your collaborators. This will take you through the necessary steps to publish your changes on Github.
After making changes to the repository you will need to stage them.
git add <file> (if you want to choose the files you want to commit)
git add <file> -f (if you want to be able to commit ignored files)
git add . (the dot is to stage every changed file)
git add . -f (this will add every changed file and inclusive ignored files)
There is one exception about staging changes, and that is when you delete files.
You can make use of git rm to delete your files, because it deletes and stages the changes at the same time.
If you made a mistake you can still recover by first unstaging your changes and then using git checkout.
git checkout -- <file> (will undo file changes)
A little advice is using as much as possible git status because it shows in what state your repository currently is.
git rm <file> (removes/stages deleted files)
git rm <file> -r (removes/stages deleted directories and everything inside)
git reset HEAD <file> (unstage chosen files)
git reset HEAD (unstage all files)
After staging you can commit your changes.
git commit
You can edit the commit message and you can add extra files if your commit was incomplete.
git add ...
git commit --amend
You can undo your commit and unstage your committed changes.
git reset HEAD~
Push your commits in the upstream.
git push
You can revert commits if mistakes were pushed.
git revert <commit hash>
Commit hashes can be found on Github or with git log.
Note:
Each time you execute git commit an editor will be prompt where you can write your commit message.
The very first time you commit, you will be given the opportunity to change your committer information.
git config --global user.name "Your Name"
git config --global user.email you@example.com
When this is done you can modify your previous commit to apply the new author.
git commit --amend --reset-author
How to merge branches and manually resolve conflicts.
Merging branches can be done on Github the same way as making pull requests.
Practical information: https://help.github.com/articles/creating-a-pull-request/
Conflicts happens while merging or pulling changes.
Example of a conflict:

Everything between "<<<<<<<" and "========" are your current changes and everything between "======" and ">>>>>>>" are the changes that failed to merge.
Following commands can help you resolve your conflicts.
git log <= shows the log of commits
git show COMMIT_HASH <= shows what changes were made in a given commit
git diff <= current changes you have made in the repository
git mergetool <= fix a conflict (with system's default graphical diff tool)
Alternative:
Merge 0-work into 1-dev.
git checkout 1-dev
git merge 0-work
If you want a public branch go on Github click where you switch branches, write the name of your branch and press ENTER key.
You can also make branches on your local repository first. For instance if you are working on something and you don't want to merge yet.
git branch <name>
git checkout <branch>
Or combine previous commands:
git checkout -b <branch>
git push <remote> <branch>
git fetch <= loads changes from the upstream
git pull <= downloads and applies the changes to your local repository