1. Installing Git
sudo apt-get install git
2. Configuring Git
$ git config --global user.name "My Name"
3. Creating a new repository - git init
$ cd Desktop/git_exercise/
4. Checking the status - git status
$ git status
$ git add hello.txt
$ git add -A
$ git add .
$ git commit -m "Initial commit."
7. Modify the last commit message:
$ git --amend
Start your Git repo anew
To remove the git file and create anew in the repo:
rm -rf .git
Add a remote repository
git remote add origin https://github.com/tutorialzine/awesome-project.git
Push to remote:
If it’s a commit on the master branch:
git push origin master
If it’s a commit on some branch named “some-branch”:
git push origin some-branch
In our workflow we shall send code to CR (code review) before it goes to QA.
Create a branch
For that you create a branch, then push the code to your branch and the pull request is done in the master branch dashboard.
$ git branch some-feature
$ git checkout some-feature
You can create the branch and go in the branch in command:
$ git checkout -b some-feature
# Edit some code
git commit -a -m "Add first draft of some feature"
$ git push origin some-branch
“After Bitbucket has her feature branch, Mary can create the pull request through her Bitbucket account by navigating to her forked repository and” clicking on P
in the side bar and then “clicking the Pull request
button in the top-right corner.“
git config --global core.excludesFile ~/.gitignore
sudo vim ~/.gitignore
edit file with:
to exclude all files ending with .css.map
for a local approach simply create and edit the .gitignore file in the affected local repository.
If the file has already been staged, remove it by using:
$ git restore --staged <file>.
All those worked:
the directory tree was:
If you accidentally sync and can’t push anymore:
hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
create a force push:
git push -f origin branchname
Set git Locally
cd in the folder were you want to clone the repo:
$ cd directory/you/clone
$ git init
$ git config user.name “Your-Username” #can be different from your github username
$ git config user.email “
$ ssh-keygen -t rsa -C “
Enter file in which to save the key (/home/username/.ssh/id_rsa): /home/username.ssh/id_rsa
copy the content of the id_rsa.pub in your github settings in your profile.
Set github local authentication to be able to clone and push:
List local branches
List remote branches
$git branch -r
List all remote and local branches
$git branch -a
See what branch you are on: