<Git Reminder>
git add
add all the files you have touched
git add .
add only specific file(s)
git add myFile.javagit add mySecondFile.txt
…
add only tracked files and ignore untracked
git add -u
git pull
git pull//orgit pull origin <branchname>
git cherry-pick
Who doesn’t like cherries ❤
You can apply the changes from another commit!
git cherry-pick <commithash>
git commit
Since you have to/must COMMIT after adding your files with a descriptive message :
git commit -m “I have done these brilliant amazing one million dollars changes, give me a beer now.”
Oh but you forgot to add something and you need to change the message on your last commit!
git commit --amend -m "New commit message"
git push
Time to push your local changes to remote!!
git push origin <yourbranch>
If you are using the base branch like “master” then just do
git push
You all done! That is it! Now, go home safely my friend. ❤
WAIT!!!
WTF !!! How I am gonna solve this?! Send HALPP :(
Conflicts usually occur when competing changes are made to the same line of a file, or when one person edits a file and another person deletes the same file.
Let’s have an example:
Let’s assume that you have a branch called “lipstick” that you have created from master -your base/origin- branch.
You have done some changes on “lipstick” branch; you did -add, commit, push- .
//You are on 'lipstick' branch
git add .
git commit -m"<commit message>"
git push origin lipstick
But you realize that you can not merge your branch with the base one since you are some commits behind master.
What to do then?
//You are on 'lipstick' branch
git checkout master
//now you are on master branch
git pull
git checkout lipstick
git merge master
//here you will see some logs on the bash just type
:wq
//then
git push origin lipstick
No more Conflicts! You are good to go to merge with master!
- If you do not see any logs on the bash and if it just says, you have conflicts on these files then
You can either go and simply check those files by looking at
<<<<<<< HEAD.... //head branch’s changes=======... //your changes you added newly>>>>>>> dd2c3d7d //your commit hash
You should remove ‘<<<<<<< HEAD // ======= // >>>>>>> dd2c3d7d
’
after deciding which part you wanna keep -both or head or your changes part.
or
you can use a tool like SourceTree to fix it easily.
Oh No!
Push rejected? Or you are working with a branch when someone is also using the same! You might have a conflict or destroy the other commits when you push!
You can say “Nah, I have a solution, I just do..”
git push --force
NO NO NO ! NEVER! JUST DON’T!
There is a safer, clever way! -always. Just do..
git push --force-with-lease
— force-with-lease gives you the flexibility to override new commits on your remote branch, whilst protecting your old commit history!
Shall we REBASE from Master ? ❤
git pull — rebase origin master
After all the chaos!
Let’s delete branches ❤
Deleting local branches in Git
git branch -d <yourbranch>
Deleting remote branches in Git
git push origin --delete <yourbranch>
That’s all for daily usage!
Hope it helps! ❤