- pull the branch(you want to change, say
master
) from remote - create a new branch, say
branch1
- commit
- pull
branch1
, just in case someone had made changes in the branch - push
branch1
- Create a
Pull Request
on github
-
Install git
sudo apt-get install git
-
Check for name
git config --global user.name
-
Configure your name
git config --global user.name "Your name"
-
Check for mail
git config --global user.email
-
Configure email
git config --global user.email "[email protected]"
-
Create a new directory with name of your choice
-
cd into that directory
-
Run following commands
git init
git remote add origin https://gitlab.com/gdadlaney/Data-Exchange-Platform.git
# "origin" is your remote_name (part of .git/refs/remotes/)git pull origin master
- OR
git clone https://gitlab.com/gdadlaney/Data-Exchange-Platform.git
# instead of the above 3 git remote -v
# lets you check the origin urls
-
After changing any file at the end of the day run following commands
git add .
# Add new/updated files to staging indexgit commit -m "message"
# Always add an informative messagegit pull origin master
# Always pull updates from remote, else remote won't remain stablegit push origin master
-
Branching
-
git checkout -b new_branch
# create a new branch & switch to it -
git checkout master
# switch to any branch -
git branch
# show all branches in current local repo -
git checkout master && git merge new_branch
# merge new_branch with master branch -
git branch -d new_branch
# delete a branch after it has been merged ( -D to remove a branch w/o merging )
-
- `git add file1 [file2 ...]`
- `git commit [file1 ...] -m "..."`
1) Split work into different commits -
Say you came for a task x, but also found some formatting that could be improved. You could commit the fix in one commit & the formatting in another, to make it easier to review changes later.
2) Keep adding changes in the staging index, which work well. If a change doesn't work well & you want to discard the changes, you can checkout the file or checkout all files - "git checkout *" to bring them to their previous staging state.
- `git commit -a`
Read more about pulling, pushing from a remote repo & merge_conflicts:
https://stackoverflow.com/questions/5601931/best-and-safest-way-to-merge-a-git-branch-into-master
- `git help <command>` OR `git help -a`
Before Staging -
# The 2 below are used together
- `git diff` # show the changes in the files made before adding them to the staging index
- `git checkout file1` # undo any changes made after the previous staging of file1
- `git ls-files` # shows the files currently in the staging-index.
- `git rm file1 file2 ...`